Page 1 of 1

Feeding SQL error into variable for use later on in code

Posted: Sat Mar 13, 2004 11:24 am
by struggling_student
In my code I have to run a query to add a database at the beginning of the code so that the table will be used in my sidebar which is included in the code.

The problem is that if the query fails due to an incorrect database name or a duplicated table name i can't output the error in the correct place on the page.

Is there anyway i can feed any error into a variable and call it at the appropriate place in the code?

Posted: Sat Mar 13, 2004 11:59 am
by McGruff
You probably want to use [php_man]mysql_errno[/php_man] or [php_man]mysql_error[/php_man]. The former is better if you don't want to give out information about database table names etc which might assist hackers.

Posted: Sat Mar 13, 2004 1:01 pm
by penguinboy
To set it to a variable:

Code: Select all

mysql_query() or ($mysql_error = mysql_error());
Or, if you have multiple querys, set it to an array element:

Code: Select all

mysql_query() or ($mysql_error[] = mysql_error());

Posted: Sat Mar 13, 2004 2:34 pm
by struggling_student
Excellent! Thanks alot!