Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show an alert box in PHP? [closed]

I want to display an alert box showing a message with PHP.

Here is my PHP code:

<?php     header("Location:form.php");    echo '<script language="javascript">';   echo 'alert(message successfully sent)';  //not showing an alert box.   echo '</script>';   exit; ?> 

But it is not working.

like image 275
prakash_d22 Avatar asked Dec 12 '12 10:12

prakash_d22


People also ask

How do I show popups in PHP?

PHP does not have the feature to pop-up an alert message box, but you can use the JavaScript code within the PHP code to display an alert message box. In this way, you can display an alert message box of JavaScript in PHP.

Why is my alert box not working in PHP?

There are many problems with your script, but to answer your key question... you are echo 'ing out the javascript code for an alert() , which will in turn prevent your php header('Location:get_estimation. php'); from executing because there has already been output sent to the browser before header was called.

Is there PHP alert?

PHP doesn't support alert message box because it is a server-side language but you can use JavaScript code within the PHP body to alert the message box on the screen.

How do I show messages in alert box?

Alert Box. Use the alert() function to display a message to the user that requires their attention. This alert box will have the OK button to close the alert box. The alert() function takes a paramter of any type e.g., string, number, boolean etc.


2 Answers

use this code

echo '<script language="javascript">'; echo 'alert("message successfully sent")'; echo '</script>'; 

The problem was:

  1. you missed "
  2. It should be alert not alery
like image 160
Yogesh Suthar Avatar answered Sep 20 '22 10:09

Yogesh Suthar


Try this:

Define a funciton:

<?php function phpAlert($msg) {     echo '<script type="text/javascript">alert("' . $msg . '")</script>'; } ?> 

Call it like this:

<?php phpAlert(   "Hello world!\\n\\nPHP has got an Alert Box"   );  ?> 
like image 41
maqs Avatar answered Sep 24 '22 10:09

maqs