Mysql insert
Jeg har disse import men den kommer med et 1 istedet for at 0, jeg bruger disse koderCREATE TABLE `main` (
`id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`dato` varchar(10) NOT NULL,
`Emne` varchar(150) NOT NULL,
`Rettelse` varchar(10000) NOT NULL,
`Source` varchar(250) NOT NULL,
`country` varchar(250) NOT NULL,
`riData` bit(1) NOT NULL,
`rtData` bit(1) NOT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
<?xml version="1.0" encoding="UTF-8"?>
-<dataroot generated="2018-05-07T12:02:40" xmlns:od="urn:schemas-microsoft-com:officedata">
-<Main>
<Dato>2012-10-23T00:00:00</Dato>
<Emne>Test</Emne>
<Rettelse>Test</Rettelse>
<Indtastet_x0020_af>Lars</Indtastet_x0020_af>
<Land>XX</Land>
<Data>0</Data>
<Rettes_x0020_i_x0020_Data>0</Rettes_x0020_i_x0020_Data>
<Souce>1</Souce>
</Main>
</dataroot>
<?php
//import.php
sleep(3);
$output = '';
if(isset($_FILES['file']['name']) && $_FILES['file']['name'] != '')
{
$valid_extension = array('xml');
$file_data = explode('.', $_FILES['file']['name']);
$file_extension = end($file_data);
if(in_array($file_extension, $valid_extension))
{
$data = simplexml_load_file($_FILES['file']['tmp_name']);
$connect = new PDO('mysql:host=localhost;dbname=test','root', '');
$query = "
INSERT INTO main
(dato,Emne,Rettelse,Source,country,riData,rtData)
VALUES(:Dato, :Emne, :Rettelse, :Souce, :Land, :Rettes_x0020_i_x0020_Data, :Data);
";
$statement = $connect->prepare($query);
for($i = 0; $i < count($data); $i++)
{
$statement->execute(
array(
':Dato' => $data->Main[$i]->Dato,
':Emne' => $data->Main[$i]->Emne,
':Rettelse' => $data->Main[$i]->Rettelse,
':Souce' => $data->Main[$i]->Souce,
':Land' => $data->Main[$i]->Land,
':Rettes_x0020_i_x0020_Data' => $data->Main[$i]->Rettes_x0020_i_x0020_Data,
':Data' => $data->Main[$i]->Data
)
);
}
$result = $statement->fetchAll();
if(isset($result))
{
$output = '<div class="alert alert-success">Import Data Done</div>';
}
}
else
{
$output = '<div class="alert alert-warning">Invalid File</div>';
}
}
else
{
$output = '<div class="alert alert-warning">Please Select XML File</div>';
}
echo $output;
?>
Nogen ide til hvorden skriver 1 i min sql istedet for 0 under Rettes_x0020_i_x0020_Data ?