When you execute
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:
echo "<script type='text/javascript'>alert(\"$error\");</script>";
Peter