Jump to content

Recommended Posts

Hi all

 

I've got a slight problem adding some XML data to a MySQL database. My code looks like: 

 

// Load XML file
$xml = simplexml_load_file('products.xml') or die ("Could not load XML file");
 
// Database variables
$host = "localhost";
$username = "user_name";
$password = "pass_word";
$dbname = "database_name";
 
// Foreach piece of XML data - send to MySQL database and put into the xmlFeed_db database
foreach ($xml->product as $data) {
 
// MySQL connect to database
$con = mysql_connect("$host", "$username", "$password") or die ("Unable to connect to database");
$select_db = mysql_select_db($dbname) or die ("Unable to select database");
 
// Put all data into numerous variables 
$id = $data->id;
$man = $data->manufacturers;
$des = $data->description;
$price = $data->price;
$sku = $data->sku;
$category = $data->category;
$subcategory = $data->subcategory;
 
// SQL statement
$query = "INSERT INTO tablename VALUES ('$id','$man','$des','$price','$sku','$category','$subcategory')";
 
// Execute SQL statement
mysql_query($query) or die ("Insertion Error: " . mysql_error());
 
// Close MySQL 
mysql_close();
 
When I run this script it only stores 249 rows out of 2000 and then it shows an error stating: 
 
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's)', '117.08','CAB-OCTAL-ASYNC=','Networking','Networking Cables')' at line 1"
 
Does anyone know why this error message is showing? I've looked at my syntax but I can't see a problem. Maybe a fresh pair of eyes can help.
 
Thanks
Edited by bigmac90
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.