1,105,286 Community Members

How to store error of mysql_error() in a php variable??

Member Avatar
shahai.ali
Light Poster
48 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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().

Member Avatar
NardCake
Posting Pro in Training
415 posts since Oct 2012
Reputation Points: 30 [?]
Q&As Helped to Solve: 30 [?]
Skill Endorsements: 9 [?]
 
0
 

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

Member Avatar
shahai.ali
Light Poster
48 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

this not help me accurately

Member Avatar
adam.adamski.96155
Junior Poster
189 posts since Oct 2012
Reputation Points: 43 [?]
Q&As Helped to Solve: 40 [?]
Skill Endorsements: 6 [?]
 
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.

Question Answered as of 1 Year Ago by adam.adamski.96155 and NardCake
Member Avatar
shahai.ali
Light Poster
48 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thnx adamadamski96155 its working here

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: