You are here:  » No Values inserted in MySql Table


No Values inserted in MySql Table

Submitted by pasturepool on Sun, 2008-06-01 15:05 in

Hello,

I am having trouble inserting records into my MySQL table. I've read through http://www.magicparser.com/node/429 to perhaps troubleshoot and I'm having the same issue as the user you assisted, yet I'm unable to resolve.

The issue is that it appears the actual values are not being found from the parse? Using the code you suggested in the above thread, I have the following results:

Processed 4 records.
Last SQL statement was: INSERT INTO tablename (field1, field2, field3) VALUES ( '', '', '')

Here is the code I used below.

require("MagicParser.php");
require_once('../../../../Connections/PastureTrack.php');
mysql_select_db($database_PastureTrack, $PastureTrack);

function myRecordHandler($record)
{

global $counter;
global $sql;
$counter++;

$sql = "INSERT INTO golfrounds (field1, field2, field3) VALUES (
'".mysql_real_escape_string($record["field1"])."',
'".mysql_real_escape_string($record["field2"])."',
'".mysql_real_escape_string($record["field3"])."')";

if (!mysql_query($sql))
{
// SQL failed, print error message and abort
print mysql_error();exit();
}
}

MagicParser_parse("http://www.myurl.com/file.xml","myRecordHandler","xml|RECORDS/RECORD/");

print "Processed ".$counter." records.";
print "Last SQL statement was: ".$sql."";

Does capitalization matter? In other words, the XML file has the nodes in CAPITAL letters, but my code above uses lowercase?

Thank you for any direction.

Submitted by support on Sun, 2008-06-01 15:45

Hello,

Yes - capitalization does matter, with XML, all the fields are in UPPER CASE, regardless of what case is used in the original XML document. So instead of:

$record["field1"]

...you need to use:

$record["FIELD1"]

Remember that you can always use print_r($record) to see exactly what the field names in your $record are...

Cheers,
David.