Hi David,
The following code throws up - Parse error: syntax error, unexpected T_RETURN in /home/.php on line 12.
<?php
require("MagicParser.php");
mysql_connect("localhost","*","*") or die(mysql_error());
mysql_select_db("*") or die(mysql_error());
$count = 0;
function myRecordHandler($record)
{
global $link;
$sql = "SELECT * FROM listings WHERE id='".mysql_escape_string($record["ID"])."'";
if (mysql_num_rows(mysql_query($sql)) return;
$sql = "
INSERT INTO `listings` SET
`id` = '".mysql_real_escape_string($record["ID"])."',
`name` = '".mysql_real_escape_string($record["NAME"])."',
`link` = '".mysql_real_escape_string($record["LINK"])."',
`addr1` = '".mysql_real_escape_string($record["ADDR1"])."',
`city` = '".mysql_real_escape_string($record["CITY"])."',
`province` = '".mysql_real_escape_string($record["PROVINCE"])."',
`postal_code` = '".mysql_real_escape_string($record["POSTAL_CODE"])."',
`description` = '".mysql_real_escape_string($record["DESCRIPTION"])."',
`phone` = '".mysql_real_escape_string($record["PHONE"])."',
`review` = '".mysql_real_escape_string($record["REVIEW"])."',
`website` = '".mysql_real_escape_string($record["WEBSITE"])."'
";
$count++;
}
mysql_query($sql) or die(mysql_error());
$filename = "http://www";
MagicParser_parse($filename,"myRecordHandler","xml|");
print "Done. ".$count." records imported.";
?>
Your assistance with this problem would be much appreciated.
Thanks
Barbara
Hi David,
Thanks for your swift response.
I get 'Query was empty' when running the code. I want to check if the listing as previously been entered in to the database, if false enter the listing.
Thanks
Barbara
Hi Barbara,
The line to execute the main SQL appears to be in the wrong place - it's just outside the myRecordHandler function so the main SQL would never actually be executed; and also explains why you get the Query was empty error. Have a go with:
<?php
require("MagicParser.php");
mysql_connect("localhost","*","*") or die(mysql_error());
mysql_select_db("*") or die(mysql_error());
$count = 0;
function myRecordHandler($record)
{
global $link;
$sql = "SELECT * FROM listings WHERE id='".mysql_escape_string($record["ID"])."'";
if (mysql_num_rows(mysql_query($sql))) return;
$sql = "
INSERT INTO `listings` SET
`id` = '".mysql_real_escape_string($record["ID"])."',
`name` = '".mysql_real_escape_string($record["NAME"])."',
`link` = '".mysql_real_escape_string($record["LINK"])."',
`addr1` = '".mysql_real_escape_string($record["ADDR1"])."',
`city` = '".mysql_real_escape_string($record["CITY"])."',
`province` = '".mysql_real_escape_string($record["PROVINCE"])."',
`postal_code` = '".mysql_real_escape_string($record["POSTAL_CODE"])."',
`description` = '".mysql_real_escape_string($record["DESCRIPTION"])."',
`phone` = '".mysql_real_escape_string($record["PHONE"])."',
`review` = '".mysql_real_escape_string($record["REVIEW"])."',
`website` = '".mysql_real_escape_string($record["WEBSITE"])."'
";
mysql_query($sql) or die(mysql_error());
$count++;
}
$filename = "http://www";
MagicParser_parse($filename,"myRecordHandler","xml|");
print "Done. ".$count." records imported.";
?>
Cheers,
David
Hi Barbara,
There is a bracket missing from the IF condition, that should be all it is - this line:
if (mysql_num_rows(mysql_query($sql)) return;
...should be:
if (mysql_num_rows(mysql_query($sql))) return;
Cheers!
David.