Reputation: 188
i am writing a php code involving mysql. At one point, i have to update a table in my database for which i am using the below 2 statements. But these are not working.
$temp = $row['tracking_id'];
mysql_query("UPDATE order_products SET state=4.00 WHERE tracking_id = '$temp'");
Note that i don't get an error message. The table is not updated though. Also note, the column names, table names are correct. I have also tried without the single '' quotes around $temp in WHERE clause.
The connection to database is fine. I know this cos select queries are working fine.
Any ideas?
Thanks
Upvotes: 0
Views: 141
Reputation: 50966
Try to var_dump temp
var_dump($temp);
and also check errors from your query
mysql_query("UPDATE order_products SET state=4.00 WHERE tracking_id = '$temp'") or trigger_error(mysql_error()." <here is that problem");
It will give you your answer
Upvotes: 3
Reputation: 157828
Note that i don't get an error message.
No wonder. You have to ask a database for the error message.
$tmp = mysql_real_escape_string($row['tracking_id']);
$sql = "UPDATE order_products SET state=4.00 WHERE tracking_id = '$tmp'";
mysql_query($sql) or trigger_error(mysql_error()." ".$sql);
var_dump(mysql_affected_rows); //to see if rows were changed.
if it prints only 0 - then you have a row with exactly same values in your table already
Upvotes: 0
Reputation: 71
How did you fetch the row?
using mysql_tetch_row
or mysql_fetch_array
?
if you used fetch_array
it's not an associative array and you can't do row['something']
, only row[index]
, so use fetch_row
instead.
print the value of temp to verify it's ok and if still can't find the problem try using the mysql_error()
function to prinT the last mysql error.
Upvotes: 0
Reputation: 1736
Firstly check what is the value in $temp.
If value is fine the do it like this to echo your query.
echo $sql = "UPDATE order_products SET state=4.00 WHERE tracking_id = '$temp'"; $result = mysql_query($sql);
its only for testing and check the query is it fine? try running it directly and see if any error comes
Upvotes: 0