0

hi all i want to store the error of mysql_error() in a variable. i was trying the following:

    $alert_error = "<script type=\"text/javascript\"> alert('".mysql_error()."') </script>";
    $id =5;
    $query = mysql_query("DELETE FROM abc WHERE id ='$id'") or die ($alert_error);

actually my there is a foreign key constraint so when i click to delete it the mysql_error()display an error but i want overwrite that error using alertbox().

Edited by shahai.ali: some error was there

3
Contributors
4
Replies
6
Views
4 Years
Discussion Span
Last Post by shahai.ali
0

$variableName = mysql_error($connection);
if you don't specify your connection it will just use the last one opened.

1

$alert_error = "<script type=\"text/javascript\"> alert('".mysql_error()."') </script>";
In the above line you are referencing 'mysql_error()', but it doesn't exist yet because you did not run the query that produces the error.
Also, you wanted Javascript to alert the value of 'mysql_error()':

if (!$query = mysql_query("DELETE FROM abc WHERE id ='$id'")){
    echo "<script type=\"text/javascript\"> alert('".mysql_error()."') </script>";
    }

The above works when I test it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.