0

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

7
  • Have you ever thought about putting '' around 4.00? Commented Aug 29, 2011 at 9:53
  • did you echo mysql_error(); ? is temp contains the correct value? did you try add '' around 4.00 ? Commented Aug 29, 2011 at 9:54
  • Try this echo "UPDATE order_products SET state=4.00 WHERE tracking_id = '$temp'" and paste the answer in mysql command line client. Should give you details of what you are missing Commented Aug 29, 2011 at 9:57
  • Yes i tried quotes around 4.00 too, didnt work Commented Aug 29, 2011 at 10:06
  • @Nibhrit: Please post the mysql_error(); you got Commented Aug 29, 2011 at 10:10

4 Answers 4

3

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

Sign up to request clarification or add additional context in comments.

4 Comments

Yeah that worked. Looks like someone deleted the table i am working on. The database is on a common server so it took a while to figure that out. mysql_error was great help. thanks
Please, don't die! That's both insecure and unusable.
@Pekka: Ah I'm blind. It definitelly isn't insecure, but unsuable, yes. Thanks for suggestion
@genesis the "insecure" bit refers to the fact that the error message is displayed even in production mode, while the assumption is that trigger_error() will not.
0

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

Comments

0

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.

1 Comment

the row fetch is working fine cos im echo-ing the contents of the row above this statement
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.