Jump to content

Mysql Update Problem


ProblemHelpPlease
 Share

Recommended Posts

I have the following code layout but the UPDATES do not work and the script returns no errors.

$result = mysql_query("SELECT * FROM blah WHERE blah = 'blah'");while($row = mysql_fetch_array($result)){mysql_query("UPDATE blah SET blah = 'blah' WHERE blah = '$row['blah']'");}

Can I use an UPDATE in the middle of the while like this?

Link to comment
Share on other sites

I had actually been using

$result = mysql_query("SELECT * FROM blah WHERE blah = 'blah'");while($row = mysql_fetch_array($result)){$blah = $row['blah'];mysql_query("UPDATE blah SET blah = 'blah' WHERE blah = '$blah'");}

But both the above and your suggestion have no effect. I was really looking to check if using a mysql_query UPDATE inside a while mysql_fetch_array was ok or if this was the cause of it not working.I dont understand why I am not seeing any error messages, if i pull the UPDATE out and run it on its own then it works so I know that the UPDATE itself is ok.

Link to comment
Share on other sites

It doesn't matter which control structures you put calls to MySQL in, MySQL doesn't check to see what the structure of the PHP code was where the call was made. If it's not running the update queries, then it's probably not looping at all, which means the select statement isn't returning any rows.It's not going to automatically print errors from MySQL, if you want to see those you need to check if an error happened (mysql_query will return false if there was an error), and use the mysql_error function to print the error message.

Edited by justsomeguy
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...