Reputation: 2715
Can't figure this one out:
$try1 = mysql_query("UPDATE com_users SET `choice_one` = 'president'");
$try2 = mysql_query("UPDATE com_users SET `choice_two` = 'president'");
echo mysql_error($try1);
echo mysql_error($try2);
That PHP code echoes nothing and properly changes choice_two, while not changing choice_one.
$try2 = mysql_query("UPDATE com_users SET `choice_two` = 'president'");
$try1 = mysql_query("UPDATE com_users SET `choice_one` = 'president'");
echo mysql_error($try1);
echo mysql_error($try2);
That PHP code echoes nothing and properly changes choice_one, while not changing choice_two.
How is it possible that the order of these update commands could cause one not to work at all?
Upvotes: 0
Views: 49
Reputation: 270607
The order of the queries will not matter. If there is additional code you are not showing, please post it...
mysql_error()
's first parameter is not the result resource, but rather the connection resource. So to get the first's error, you need to call it immediately after the first query.
$try1 = mysql_query("UPDATE com_users SET `choice_one` = 'president'");
// Call with no parameter right after the query it relates to.
echo mysql_error();
$try2 = mysql_query("UPDATE com_users SET `choice_two` = 'president'");
echo mysql_error();
Note that you are not using a WHERE
clause, all rows will be updated the first time. The second time you try running those queries (unless you have reset your data), there will be no rows needing updating and the query will have no effect (mysql_affected_rows() == 0
).
Upvotes: 2