Alert Message and Page Redirect Not Working Inside PHP
This page all about why alert message and page redirect not working inside PHP. Sometimes you have faced this kind of issue, Suppose for an example if someone submit the form and after data inserts in the database successfully then he wants to show the alert message. In that particular scenario If we echo some javascript inside the PHP script, then redirecting with PHP script like below example it will not work. So we need to change a line of code so that it will work fine in second example.
It Will won’t Work
Example-1:
1 2 |
echo "<script type='text/javascript'>alert('Lead added successfully');</script>"; header('leadslist.php',"refresh"); |
Example-2:
Do This Way, it will Work for Sure:
1 |
echo "<script type='text/javascript'>alert('Lead added successfully');location='leadslist.php';</script>"; |