我創建了一個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>";
}
}
}
?>
if(成功) - >這是一個函數或變量,如果這是一個變量,它應該是$ success。這一套是什麼時候? –