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.
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.
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.
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.
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.
use this code
echo '<script language="javascript">'; echo 'alert("message successfully sent")'; echo '</script>';
The problem was:
"
alert
not alery
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" ); ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With