MySQL Forums
Forum List  »  Connector/Node.js

upload xml file into mysql table
Posted by: Daniel CPrakash
Date: May 19, 2009 12:24AM

Hai,

the following code i have created in php it update only 4 fields of the table can any one fix this

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);

$p = xml_parser_create(); //Create XML parser and get a handle

//file(filename) reads file in an array
//implode will give data string to be inserted into database

$data = implode("",file("order.xml")) or die(mysql_error());

xml_parser_set_option($p,XML_OPTION_CASE_FOLDING,0);//Will not convert tags in upper case

xml_parser_set_option($p,XML_OPTION_SKIP_WHITE,1); //Probably will skip white spaces not sure


xml_parse_into_struct($p,$data,$vals,$index); //Read from manual

xml_parser_free($p); //Free parser

$i=1;

while($i < count($vals)-1)
{
if($vals[$i][tag]=="order_details")
{
$i++;
continue;
}
$val_index=$i;
$j=0;
while($j < count($vals[$val_index]))
{
$value_array[$j]=$vals[$val_index][value];
$val_index++;
$j++;
}

$i=$val_index-1;
echo $i;
mysql_query("insert into order_details VALUES($value_array[0],'$value_array[1]','$value_array[2]','$value_array[3]','$value_array[4]','$value_array[5]','$value_array[6]','$value_array[7]','$value_array[8]','$valu_array[9]','$value_array[10]','$value_array[11]','$value_array[12]','$value_array[13]','$value_array[14]','$value_array[15]','$value_array[16]',' $value_array[17]',' $value_array[18]',' $value_array[19]') ") or die("Could not insert into table order_details.".mysql_error());
$i++;
}


?>

Options: ReplyQuote


Subject
Written By
Posted
upload xml file into mysql table
May 19, 2009 12:24AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.