64

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.

Community
  • 1
  • 1
prakash_d22
  • 1,153
  • 5
  • 21
  • 34
  • 4
    Why do you want header("Location:form.php") at the top? If you want to redirect the user to form.php AFTER the alert, you should just redirect the user in the Javascript as such : echo 'location.href="form.php"'; – ashiina Dec 12 '12 at 10:39
  • 1
    Look what you have written => echo 'alery(message successfully sent)'; //not showing an alert box. It should be alery not akery. – Pratik Joshi Mar 10 '14 at 05:01

9 Answers9

162

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
Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
29

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"   );  ?>
maqs
  • 414
  • 4
  • 5
5

There is a syntax error (typo):

It's alert not alery.

OneMore
  • 1,139
  • 2
  • 9
  • 19
Muhammad Talha Akbar
  • 9,952
  • 6
  • 38
  • 62
5
echo "<script>alert('same message');</script>";

This may help.

Pang
  • 9,564
  • 146
  • 81
  • 122
Prakash Madhak
  • 347
  • 3
  • 11
4
echo '<script language="javascript>';

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

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

This should do.

ashiina
  • 996
  • 1
  • 7
  • 21
2

change your output from

 echo '<script language="javascript>';

to

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

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

silly
  • 7,789
  • 2
  • 24
  • 37
2
echo '<script language="javascript">';
echo 'alert("message successfully sent")';
echo '</script>';
Akhilraj N S
  • 9,049
  • 5
  • 36
  • 42
2

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.

CE_REAL
  • 384
  • 5
  • 13
1

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

enter code here
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>';

Try to change this with :

  echo
  "<script>
  alert('Sent Successfully');
  document.location.href = 'index.php';
  </script>
  ";
Community
  • 1
  • 1
faid
  • 375
  • 1
  • 4
  • 19