Solved

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

Posted on 2013-01-17
4
427 Views
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 http://www.cu.in

<?php
$con = mysql_connect("xxxxxx","xxxxx","xxx");
if (!$con)
{
       die('Could not connect: ' . mysql_error());
}
mysql_select_db("695818_chndu", $con);
$NAME=$_POST['NAME'];
$FNAME=$_POST['FNAME'];
$ADDRESS=$_POST['ADDRESS'];
$LANDLINENO=$_POST['LANDLINENO'];
$CONTACTNO=$_POST['CONTACTNO'];
$EMAIL=$_POST['EMAIL'];
$ACADEMIC=$_POST['ACADEMIC'];
$SPORTS=$_POST['SPORTS'];
$ACTIVITY=$_POST['ACTIVITY'];
$DType=$_POST['DType'];
$course="";
if ($DType=='Grad')
{
$course=$_POST['GCOURSE'];
}
else if($DType=='PostGrad')
{
$course=$_POST['PGCOURSE'];
}
else
{
$course=$_POST['DCOURSE'];
}
$frm=$_POST['FROMWHERE'];
$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())";
mysql_query($sql,$con);
mysql_error();
mysql_close($con);
header('location:http://www.cu.in');
?>
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
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 = \"http://www.cu.in\";</script></head></html>");

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

Assisted Solution

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

header('Location: http://www.cu.in/index.php?success=1');
die();

(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:

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

Expert Comment

by:gr8gonzo
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.
0
 

Author Closing Comment

by:searchsanjaysharma
ID: 38792444
tx
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

751 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