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?
Feeding SQL error into variable for use later on in code
Moderator: General Moderators
-
struggling_student
- Forum Newbie
- Posts: 15
- Joined: Mon Feb 23, 2004 3:51 pm
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.
Last edited by McGruff on Tue Aug 09, 2005 11:56 am, edited 1 time in total.
-
penguinboy
- Forum Contributor
- Posts: 171
- Joined: Thu Nov 07, 2002 11:25 am
To set it to a variable:
Or, if you have multiple querys, set it to an array element:
Code: Select all
mysql_query() or ($mysql_error = mysql_error());Code: Select all
mysql_query() or ($mysql_error[] = mysql_error());-
struggling_student
- Forum Newbie
- Posts: 15
- Joined: Mon Feb 23, 2004 3:51 pm