PDA

View Full Version : trap MySQL errors


B&T
7-14-03, 12:31 AM
I have this:

$query = mysql_query("UPDATE $table SET $vote = $vote + 1 WHERE id=$id") or sql_error("vote","mysql_error()");

but the error routine sql_error does not get the error information, instead it gets the words "mysql_error()".

I have tried in and out of quotes with a .$query. cannot get the error information passed.

Anyone know the correct syntax for this?

Second question:

I have this:

$count = mysql_result(mysql_query("SELECT COUNT(id) FROM $table"),0);

which works fine. but I would like to put an "or sql_error( . . . . )" in that statement as well. I have tried different things, none of which work.

Anyone know the correct syntax for that?

Just trying to clean up some of my code so I trap all of my potential errors.

HalfaBee
7-14-03, 01:03 AM
Your not getting the error because you have mysql_error inside quotes.

The second problem you can only resolve by using two seperate lines for the statements.

HalfaBee

B&T
7-14-03, 01:07 AM
Halfabee -

Thanks for responding:

for the first one - took the quotes off and all is well - I thought I had tried that before, but I must have had something else wrong.

for the second question. this worked:

$query = mysql_query("SELECT COUNT(id) FROM $table") or sql_error("count",mysql_error());
$count = mysql_result($query,0);