Javascript 提交数据时不显示警告框
有很多类似的问题,但我没有任何错误,我需要做一些改变 我已经在我的代码中添加了警告框,但没有出现警告框 这是我的密码-Javascript 提交数据时不显示警告框,javascript,php,mysql,Javascript,Php,Mysql,有很多类似的问题,但我没有任何错误,我需要做一些改变 我已经在我的代码中添加了警告框,但没有出现警告框 这是我的密码- if(isset($_POST['submit'])){ $test= "select * from stable where Email = '$Email'"; $queryResult = $conn->query($test); $foundRows = $queryResult->num_rows; if($foundRo
if(isset($_POST['submit'])){
$test= "select * from stable where Email = '$Email'";
$queryResult = $conn->query($test);
$foundRows = $queryResult->num_rows;
if($foundRows >= 1)
$mailerr="Email already register";
else {
header("location:student.php?id=".$row['id']);
$sql = "INSERT INTO stable
(Firstname,Lastname,DOB,Email,Phno,
Gender,Address,City,ZipCode,State,Country,
Hobbies,Course,id,Time,Date,IP)
VALUES('$Firstname','$Lastname','$Dob','$Email',
'$Phno','$Gender','$Address','$City','$Zipcode',
'$State','$Country','$Hobby','$Course','',
'$Time','$date','$IP')";
if($conn->query($sql))
?>
<script> alert('Data Inserted successfully');
window.location.href='student.php?id=<?php echo $id;?>' </script>
<?php
}
}
if(isset($\u POST['submit'])){
$test=“选择*from stable,其中Email='$Email';
$queryResult=$conn->query($test);
$foundRows=$queryResult->num_行;
如果($foundRows>=1)
$mailerr=“电子邮件已注册”;
否则{
标题(“location:student.php?id=”.$row['id']);
$sql=“插入到稳定的
(名字、姓氏、DOB、电子邮件、Phno、,
性别、地址、城市、邮编、州、国家、,
兴趣爱好、课程、id、时间、日期、IP)
值(“$Firstname”、“$Lastname”、“$Dob”、“$Email”,
“$Phno”、“$Gender”、“$Address”、“$City”、“$Zipcode”,
“$State”、“$Country”、“$Hobby”、“$Course”、”,
“$Time”、“$date”、“$IP”)”;
如果($conn->query($sql))
?>
警报(“数据插入成功”);
window.location.href='student.php?id='
试试这个:
if(isset($_POST['submit'])){
$test= "select * from stable where Email = '$Email'";
$queryResult = $conn->query($test);
$foundRows = $queryResult->num_rows;
if($foundRows >= 1)
$mailerr="Email already register";
else {
header("location:student.php?id=".$row['id']);
$sql = "INSERT INTO stable
(Firstname,Lastname,DOB,Email,Phno,
Gender,Address,City,ZipCode,State,Country,
Hobbies,Course,id,Time,Date,IP)
VALUES('$Firstname','$Lastname','$Dob','$Email',
'$Phno','$Gender','$Address','$City','$Zipcode',
'$State','$Country','$Hobby','$Course','',
'$Time','$date','$IP')";
if($conn->query($sql)){
echo "<script type='text/javascript'>alert('Data Inserted successfully');
window.location.href='student.php?id=".$id."';
</script>";
}
}
}
if(isset($\u POST['submit'])){
$test=“选择*from stable,其中Email='$Email';
$queryResult=$conn->query($test);
$foundRows=$queryResult->num_行;
如果($foundRows>=1)
$mailerr=“电子邮件已注册”;
否则{
标题(“location:student.php?id=”.$row['id']);
$sql=“插入到稳定的
(名字、姓氏、DOB、电子邮件、Phno、,
性别、地址、城市、邮编、州、国家、,
兴趣爱好、课程、id、时间、日期、IP)
值(“$Firstname”、“$Lastname”、“$Dob”、“$Email”,
“$Phno”、“$Gender”、“$Address”、“$City”、“$Zipcode”,
“$State”、“$Country”、“$Hobby”、“$Course”、”,
“$Time”、“$date”、“$IP”)”;
如果($conn->query($sql)){
echo“警报('数据插入成功');
window.location.href='student.php?id=“.id$”;
";
}
}
}
您可以将脚本标记和所有js打包在字符串中,并对其进行回显。它会起作用的
if($conn->query($sql)){
echo "<script> alert('Data Inserted successfully')window.location.href='student.php?id="+$id+"</script>";
}
if($conn->query($sql)){
echo“警报('成功插入数据')窗口。location.href='student.php?id=“+$id+”;
}
这一行:标题(“location:student.php?id=”.$row['id']);
执行服务器端重定向,因此包含警报的脚本永远不会实际得到输出。因为您之后要执行JS重定向,所以您可能不需要服务器端重定向。(尽管有比JS警报更好的验证方法。)非常喜欢oaky.thakyou。这一行:header(“location:student.php?id=“.row['id']);执行服务器端重定向,我也在脚本中重定向。事情就是这样