-3

I have to reload automatically to my home after done following coding

if($sql) 
{
    echo "Updated successfully";
}else {
    echo "Con not update" . mysql_error();
} 

this is process.php page here I am writing some coding after executing my query I need to redirect to my home.php page with pop up message if $sql updated successfully message(successfully) if not error message.

Haither Ali
  • 183
  • 1
  • 10

2 Answers2

1

You need to use JavaScript for both alert and redirection.

if($sql) {
  echo "<script>alert('Updated successfully');
  window.location.href='home.php';
  </script>";
}
else {
  echo "Con not update" . mysql_error();
} 
Pupil
  • 23,834
  • 6
  • 44
  • 66
1

Also, in pure PHP, without writing a piece of JavaScript code, you can do this:

Header('Location: home.php');

This code is plenty functional on PHP an it redirects you to the requested page.

  • Might wanna tell him that he needs to remove the `echo` lines if he wants to use header, otherwise he'll just get a error. – Epodax Nov 05 '15 at 09:29
  • This is fair enough unless the output buffers have already been sent (which they will have been as he's using echo). He'll either have to ensure he sends no output prior to issuing the header or use output buffering. – GordonM Nov 05 '15 at 09:31
  • l've just wrote a simple PHP code echoing a 'Hello' and calling the Header function and it works well. What's the inner problem with echoing before the Header function? I didn't know it – David de los Santos Boix Nov 05 '15 at 09:32
  • @DaviddelosSantosBoix If you have output buffering enabled (which I suspect you must do if your test script worked) then it will be fine. If you don't, then content might have already been sent by the time you try to append a new header. By the time you're getting content, all headers must have already been sent and you won't be able to send more. Try turning output buffering off in your config, or try the following: `ob_end_flush (); echo "hello\n"; header ("Location: http://www.stackoverflow.com/");` and you should get a "headers already sent" error. – GordonM Nov 05 '15 at 09:38
  • 1
    @GordonM Yes, you have reason, I've just tried and it returns an error like the one you describe. Thanks for the information :) – David de los Santos Boix Nov 05 '15 at 09:41