Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I would like to alert the SQL error message, but alert is not coming.
"Access denied for user 'root'@'localhost'(using password: YES)"
is the error message.
PHP
<head>
    <title>Untitled Page</title>
</head>
<body>
<?php 
$con=mysql_connect("localhost","root","123");
if(!$con)
{
$error=mysql_error();
echo "<script type='text/javascript'>alert(<?php echo $error; ?>);</script>";
}

?>

</body>
</html>
Posted
Updated 29-Feb-12 10:28am
v2

1 solution

When you execute
PHP
echo "<script type='text/javascript'>alert(<?php echo $error; ??>);</script>";

you are already "in" PHP, so you don't need another (nested) enter/exit.
However, you will need to provide quotes around the string argument to alert(), because that's a javascript function executed in the browser, not PHP on the server.
Try this instead:
PHP
echo "<script type='text/javascript'>alert(\"$error\");</script>";


Peter
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900