I am using standard code to insert an XML file into MySQL using the following (just a partial code snippet below). The code works perfectly. The question is how do I include inserting Variable Y which is not part of the XML file, but being passed to the php page? Again, the code works, but varY is a variable I set within the script and is not in the XML file.
........
$sql = "INSERT INTO golfrounds (var1, varY, var2, var3)) VALUES (
'".mysql_real_escape_string($record["var1"])."',
'".mysql_real_escape_string($record["var2"])."',
'".mysql_real_escape_string($record["var3"])."')";
........
$url = "http://www.site.com/file.xml";
MagicParser_parse($url,"myRecordHandler","xml|NOTES/NOTE/");
Always the simple answers that drive me nuts. I must have been staring at the screen too long. Works perfectly!!!
Outstanding as always!
thanks
Hi,
All you would need to do is use either $_GET (if the variable has been passed to your script in the URL) or $_POST if the variable has been POSTed to your script; and you don't need to declare them as global within myRecordHandler because $_GET and $_POST are "Superglobals"... For example:
$sql = "INSERT INTO golfrounds (var1, varY, var2, var3)) VALUES (
'".mysql_real_escape_string($record["var1"])."',
'".mysql_real_escape_string($_GET["varY"])."',
'".mysql_real_escape_string($record["var2"])."',
'".mysql_real_escape_string($record["var3"])."')";
If you are receiving varY some other way then the code would be pretty much the same, but don't forget to global in varY at the top of myRecordHandler().
Hope this helps!
Cheers,
David.