I have created an html form for registering and when a user has successfully registered I want them to be automatically redirected back to my index.html page and for an alert to pop up tell them they have Registered Successfully. Currently my alert works but it just opens up in a blank page. I have tried putting in header ("location:../index.html") but that has not worked, it just directs me straight to the page without giving me the alert i want. Can anyone help with this?
<?php
$con = mysql_connect("localhost","root","") or die(mysql_error());
$select_db = mysql_select_db("mayan",$con);
if(isset($_POST['register']))
{
$firstname=$_POST['first_name'];
$lastname=$_POST['last_name'];
$address=$_POST['address'];
$postcode=$_POST['postcode'];
$emailaddress=$_POST['emailaddress'];
$password=$_POST['password'];
$query = "select emailaddress FROM mayan_users where emailaddress='$emailaddress'";
$link = mysql_query($query)or die(mysql_error());
$num = mysql_num_rows($link);
if ($num>0){
echo 'Email already exists'; //email already taken
}
else {
$insert_query = "insert into `mayan_users`(`firstname`,`lastname`,`address`,`postcode`,`emailaddress`,`password`) values('$firstname','$lastname','$address','$postcode','$emailaddress','$password')";
$result = mysql_query($insert_query)or die(mysql_error());
if(success)
{
echo "<script type=\"text/javascript\">".
"alert('success');".
"</script>";
}
}
}
?>
Use this function when redirecting:
So you want to redirect to the same page but with a ?=XXX Get value
Your code would look something like this: