Anaes Arias
Anaes Arias

Reputation: 49

How can I use javascript to alert these PHP error messages?

How can I javascript alert my php error messages? Here is my code:

<?php echo showmessage($msg)?>

I want to make it into an alert, how can I do that?

Upvotes: 1

Views: 65

Answers (2)

Waclock
Waclock

Reputation: 1726

 ?>
  <script type="text/javascript">
    alert("The error is  <?php echo $msg ?>");
    history.back();
  </script>
<?php

Or

echo '<script language="javascript">';
echo 'alert(Message here)';
echo '</script>';

Upvotes: 1

plalx
plalx

Reputation: 43728

The use of json_encode makes sure that characters that needs to be escaped are escaped.

<script>
  alert(<?php echo json_encode($msg); ?>);
</script>

Upvotes: 1

Related Questions