我创建了一个用于注册的 html 表单,当用户成功注册时,我希望他们自动重定向回我的index.html
页面,并弹出警报告诉他们他们已成功注册。目前我的警报有效,但它只是在空白页中打开。我尝试过输入, header ("location:../index.html")
但没有奏效,它只是将我直接引导到页面而没有给我想要的警报。有人能帮忙吗?
<?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>";
}
}
}
?>