How to redirect the page to home page, and display message in alert.

Posted on 2013-01-17
Last Modified: 2013-01-18
I have a .html page i.e the registration form, the user fills the form, we read the cotents and pass to .php page through $_POST and insert the record in a table.
The data is getting inserted.
Registration form name is admform.htm
The code of php file is save.php
When the user clicks on Submit button on admform.htm
the code of save.php works.
The code is as follows
At last after the mysql_close($con); line,
I want the alert message as "record saved successfully" and then the page should be redirected to

$con = mysql_connect("xxxxxx","xxxxx","xxx");
if (!$con)
       die('Could not connect: ' . mysql_error());
mysql_select_db("695818_chndu", $con);
if ($DType=='Grad')
else if($DType=='PostGrad')
$sql="insert into chdu_aa(sname,fname,address,landline,mobile,semail,coursetype,course,academic,sports,eca,source,flag,feeddate) values('".$NAME."','".$FNAME."','".$ADDRESS."','".$LANDLINENO."','".$CONTACTNO."','".$EMAIL."','".$DType."','".$course."','".$ACADEMIC."','".$SPORTS."','".$ACTIVITY."','".$frm."',".'0'.",CURDATE())";
Question by:searchsanjaysharma
  • 2

Accepted Solution

DanielSV earned 250 total points
ID: 38787209
If I understand what you want, you need to serve html+js to show the alert, then use JS to redirect.

print("<html><head><script type=\"text/javascript\">alert(\"record saved successfully\"); document.location = \"\";</script></head></html>");

The alternative is having the landing page show the alert when you arrive at it.
LVL 34

Assisted Solution

gr8gonzo earned 250 total points
ID: 38787212
Your header should probably look like:


(Assuming index.php is your home page - just use whatever the filename is)

Then in your homepage, check for $_GET["success"] in the body and display the alert:

if(isset($_GET["success"]) && ($_GET["success"] == 1))
  echo '<script type="text/javascript">alert("Record saved successfully!");</script>';
LVL 34

Expert Comment

ID: 38787221
Actually, I apologize, my example showed the alert in the homepage. If you want it shown on the previous page before redirecting, DanielSV has the correct answer, although in addition to what he said, you'll have to take out the header() line.

Author Closing Comment

ID: 38792444

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Why do people dis php? 5 47
Loop through multiple arrays 13 27
FrontEnd tools to create web database application 7 54
PHP not parsing ' character 12 37
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question