PDA

View Full Version : PHP script parsing XML and dumping to MySQL DB...it works, but!!


Medar
10-22-2002, 09:17 PM
I have a PHP page written to parse a remote XML page - take the data, assign it to variables, and INSERT it into a local MySQL database. Works like a charm...

However, my next phase is this. Instead of erasing the entire table every time this data updates (which is how I have it written now), I would like to add some fields to the table for local additional info. This means I will need to UPDATE instead of DELETE and INSERT. Here are the two subs I have now that accomplish the insert...

function print_name_tr($char)
{
global $GROUP;

// Assigning XML output to PHP variables
$daname = $char->name;
$dalaston = $char->laston;
$daclass = $char->class;
$dalevel = $char->level;
$datotalrp = $char->totalrp;
$dalastweekrp = $char->lastrp;
$daanon = $char->anon;

// Connecting to the MySQL database.
MYSQL_CONNECT(localhost, USER, PASS) OR DIE("Unable to connect to database");
@mysql_select_db("DBNAME") or die("Unable to select database");

// INSERTING data...here is where my update attempt failed.
$sqlupdate2 = "INSERT INTO da_updates VALUES('','$daname','$dalaston','$daclass','$dalev
el','$datotalrp','$dalastweekrp','$daanon')";

$result = MYSQL_QUERY($sqlupdate2);

// Visible output on the php page...using this for error checking
echo <<<EOT
$daname, $dalevel - Updating...<br>

EOT;
}

// This function calls the INSERT function, and starts the loop for the multiple $daname 's.

function print_default()
{
global $CHARS;
global $SCRIPT_NAME, $sortby;
global $server, $groupid;

foreach($CHARS as $char)
{
print_name_tr($char);
}
}

Now the $daname XML variable does not change...so I should just be able to change the INSERT INTO to an UPDATE ... WHERE da_name=$daname ... but that didn't work.

Any suggestions or help? Thanks!

Medar
10-23-2002, 09:35 PM
Argh! Nothing? Heheh...still working on this.

mordred
10-23-2002, 10:22 PM
You lost me somewhere in the middle.

Originally posted by Medar
Now the $daname XML variable does not change...


Why should it? You don't assign a new value to it.

so I should just be able to change the INSERT INTO to an UPDATE ... WHERE da_name=$daname ... but that didn't work.

Well, it would be nice to see your malfunctioning code, since that makes debugging a lot easier. If you see that your SQL command did not execute as intended, you can use mysql_error() to retrieve more information about the last error that occured while processing your query.

Have you made sure that the objects are all passed correctly to print_name_r?