Copy link to clipboard
Copied
Hi,
I am trying to update my database with the following code but even though the code definately runs because it does get to the echos on the line before the update, the database is not getting updated.
if ($totalRows_rsportsale >'0') {
$_POST['dpaid'] = 1;
$_POST['listedby'] = $row_rsportid['listedid'];
echo 'dpaid is: ' . $_POST['dpaid'] . '<br />';
echo 'listedby is: ' . $_POST['listedby'] . '<br />';
$updateSQL = sprintf("UPDATE detailstable SET dpaid=%s WHERE listedby=%s",
GetSQLValueString($_POST['listedby'], "int"),
GetSQLValueString($_POST['dpaid'], "int"));
mysql_select_db($database_connUpdate, $connUpdate);
$Result1 = mysql_query($updateSQL, $connUpdate) or die(mysql_error());
}
The values that i want to update in the database are being echoed right before the update script, so the values are correct for dpaid and listedby, i have entered the update bit of the code in the sql in myphp admin and that does update the database. The connection for the database connUpdate is correct. Both fields are "int" in the database and are not primary keys or unique. Any suggestions as to why this update is not working would be much appreciated.
Thank you in advance.
No, I don't mean the order of SQL clauses, I mean the order of the two parameters you are using.
$updateSQL = sprintf("UPDATE detailstable SET dpaid=%s WHERE listedby=%s",
GetSQLValueString($_POST['listedby'], "int"),
GetSQLValueString($_POST['dpaid'], "int"));
As I said, I don't know PHP or the sprintf command, but I would assume that it replaces the parameters (%s) in the order they are listed. Your SQL statement paramet
...Copy link to clipboard
Copied
I don't know PHP, but it seems like you have your parms listed in the wrong order. Your set value is listed after your where clause value. Right?
Copy link to clipboard
Copied
I´m pretty sure i have things in the right order, UPDATE, SET, WHERE. and I have other updates in my site that work on this format. I think I must be missing something obvious but cannot see it.
Look forward to further suggestions.
Copy link to clipboard
Copied
No, I don't mean the order of SQL clauses, I mean the order of the two parameters you are using.
$updateSQL = sprintf("UPDATE detailstable SET dpaid=%s WHERE listedby=%s",
GetSQLValueString($_POST['listedby'], "int"),
GetSQLValueString($_POST['dpaid'], "int"));
As I said, I don't know PHP or the sprintf command, but I would assume that it replaces the parameters (%s) in the order they are listed. Your SQL statement parameters (listedby and dpaid) are in the reverse order. Try switching them.
$updateSQL = sprintf("UPDATE detailstable SET dpaid=%s WHERE listedby=%s",
GetSQLValueString($_POST['dpaid'], "int")),
GetSQLValueString($_POST['listedby'], "int");
Copy link to clipboard
Copied
I see now what you mean. As suggested I swapped the params and all works perfectly.
Thank you ever so much for your help, much appreciated.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more