How to show an alert box in PHP?

PhpJavascriptHtmlAlert

Php Problem Overview


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 Solutions


Solution 1 - Php

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

Solution 2 - Php

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"   );  ?>

Solution 3 - Php

There is a syntax error (typo):

It's alert not alery.

Solution 4 - Php

echo '<script language="javascript>';

Seems like a simple typo. You're missing a double-quote.

echo '<script language="javascript">';

This should do.

Solution 5 - Php

echo "<script>alert('same message');</script>";

This may help.

Solution 6 - Php

change your output from

 echo '<script language="javascript>';

to

 echo '<script type="text/javascript">';

you forgot double quotes... and use the type tag

Solution 7 - Php

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

Solution 8 - Php

When I just run this as a page

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

it works fine.

What version of PHP are you running?

Could you try echoing something else after: $testObject->split_for_sms($Chat);

Maybe it doesn't get to that part of the code? You could also try these with the other function calls to check where your program stops/is getting to.

Hope you get a bit further with this.

Solution 9 - Php

I don't know about php but i belive the problem is from this :

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

Try to change this with :

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionprakash_d22View Question on Stackoverflow
Solution 1 - PhpYogesh SutharView Answer on Stackoverflow
Solution 2 - PhpmaqsView Answer on Stackoverflow
Solution 3 - PhpMuhammad Talha AkbarView Answer on Stackoverflow
Solution 4 - PhpashiinaView Answer on Stackoverflow
Solution 5 - PhpPrakash MadhakView Answer on Stackoverflow
Solution 6 - PhpsillyView Answer on Stackoverflow
Solution 7 - PhpAkhilraj N SView Answer on Stackoverflow
Solution 8 - PhpCE_REALView Answer on Stackoverflow
Solution 9 - PhpfaidView Answer on Stackoverflow