hey people,
i have the following problem, i'm setting up a webshop with over 2k items and every 6months the prices are changing(wines) so i was wondering how to import an xml file into a mysql database without having to go in phpmyadmin. this because i don't want the people for who i'm making the website have access there to destroy the whole database. this is what i got so far:
<?php
include "header.php";
?>
<br><br><br>
<h1>Database updaten</h1>
<form enctype="multipart/form-data"
action="import.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="20000000" />
<table width="600">
<tr>
<td>Names file:</td>
<td><input type="file" name="file" /></td>
<td><input type="submit" value="Upload" /></td>
</tr>
</table>
</form>
</body>
</html>
here i choose the file i want to import,
and then i run true the following script:
<?php
include ("header.php");
$query = "TRUNCATE TABLE `wijnen`";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$data = array();
function add_person( $id, $domein, $naam, $land, $streek, $substreek, $jaar, $type, $smaak, $formaat, $druivensoort, $prijsnormaal,
$prijs6, $prijs12, $prijs24, $info, $actieid, $afbeelding, $kleur, $titel, $description, $keywords, $afbeeldingalt, $spijs, $leverancier, $levertijd )
{
global $data;
$data []= array(
'id' => $id,
'domein' => $domein,
'naam' => $naam,
'land' => $land,
'streek' => $streek,
'substreek' => $substreek,
'jaar' => $jaar,
'type' => $type,
'smaak' => $smaak,
'formaat' => $formaat,
'druivensoort' => $druivensoort,
'prijsnormaal' => $prijsnormaal,
'prijs6' => $prijs6,
'prijs12' => $prijs12,
'prijs24' => $prijs24,
'info' => $info,
'actieid' => $actieid,
'afbeelding' => $afbeelding,
'kleur' => $kleur,
'titel' => $titel,
'description' => $description,
'keywords' => $keywords,
'afbeeldingalt' => $afbeeldingalt,
'spijs' => $spijs,
'leverancier' => $leverancier,
'levertijd' => $levertijd
);
}
if ( $_FILES['file']['tmp_name'] )
{
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$first_row = true;
foreach ($rows as $row)
{ if ( !$first_row )
{
$id = "";
$domein = "";
$naam = "";
$land = "";
$streek = "";
$substreek = "";
$jaar = "";
$type = "";
$smaak = "";
$formaat = "";
$druivensoort = "";
$prijsnormaal = "";
$prijs6 = "";
$prijs12 = "";
$prijs24 = "";
$info = "";
$actieid = "";
$afbeelding = "";
$kleur = "";
$titel = "";
$description = "";
$keywords = "";
$afbeeldingalt = "";
$spijs = "";
$leverancier = "";
$levertijd = "";
$index = 1;
$cells = $row->getElementsByTagName( 'Cell' );
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;
if ( $index == 1 ) $id = $cell->nodeValue;
if ( $index == 2 ) $domein = $cell->nodeValue;
if ( $index == 3 ) $naam = $cell->nodeValue;
if ( $index == 4 ) $land = $cell->nodeValue;
if ( $index == 5 ) $streek = $cell->nodeValue;
if ( $index == 6 ) $substreek = $cell->nodeValue;
if ( $index == 7 ) $jaar = $cell->nodeValue;
if ( $index == 8 ) $type = $cell->nodeValue;
if ( $index == 9 ) $smaak = $cell->nodeValue;
if ( $index == 10 ) $formaat = $cell->nodeValue;
if ( $index == 11 ) $druivensoort = $cell->nodeValue;
if ( $index == 12 ) $prijsnormaal = $cell->nodeValue;
if ( $index == 13 ) $prijs6 = $cell->nodeValue;
if ( $index == 14 ) $prijs12 = $cell->nodeValue;
if ( $index == 15 ) $prijs24 = $cell->nodeValue;
if ( $index == 16 ) $info = $cell->nodeValue;
if ( $index == 17 ) $actieid = $cell->nodeValue;
if ( $index == 18 ) $afbeelding = $cell->nodeValue;
if ( $index == 19 ) $kleur = $cell->nodeValue;
if ( $index == 20 ) $titel = $cell->nodeValue;
if ( $index == 21 ) $description = $cell->nodeValue;
if ( $index == 22 ) $keywords = $cell->nodeValue;
if ( $index == 23 ) $afbeeldingalt = $cell->nodeValue;
if ( $index == 24 ) $spijs = $cell->nodeValue;
if ( $index == 25 ) $leverancier = $cell->nodeValue;
if ( $index == 26 ) $levertijd = $cell->nodeValue;
$index += 1;
}
add_person( $id, $domein, $naam, $land, $streek, $substreek, $jaar, $type, $smaak, $formaat, $druivensoort, $prijsnormaal, $prijs6, $prijs12, $prijs24, $info, $actieid, $afbeelding, $kleur, $titel, $description, $keywords, $afbeeldingalt, $spijs, $leverancier, $levertijd );
}
$first_row = false;
}
}
foreach($data as $row)
{
$rowz = mysql_real_escape_string($row['domein']);
mysql_query("insert into wijnen values('','$rowz','$row[naam]','$row[land]','$row[streek]','$row[substreek]','$row[jaar]','$row[type]','$row[smaak]',
'$row[formaat]','$row[druivensoort]','$row[prijsnormaal]','$row[prijs6]','$row[prijs12]','$row[prijs24]','$row[info]','$row[actieid]','$row[afbeelding]',
'$row[kleur]','$row[titel]','$row[description]','$row[keywords]','$row[afbeeldingalt]','$row[spijs]','$row[leverancier]','$row[levertijd]')");
}
echo "<META HTTP-EQUIV='refresh' CONTENT='2; URL=bestandkiezen.php'>";
?>
now my problem, when i have signs like ë ï ö ü ä é í ó ú á and so on they aren't parsed into the database the correct way. anyone knows how i can solve this?