代码本身正在运行,但是我唯一的问题是警报框。下面是我的代码,用于确认表中的categoryID是否与另一个表的categoryID相同。我的担心是。在进入该位置之前,不会弹出带有$message
的变量echo "<script type='text/javascript'>alert('$message');</script>";
。我想要的是当两个categoryID不匹配时。我想在进入位置header("Location:addpost.php");
但是当我删除header("Location:addpost.php");
并保留echo "<script type='text/javascript'>alert('$message');</script>";
时。它会弹出。
谢谢您的帮助!
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
include "dbconnect.php";
$message = "wrong answer";
if (isset($_GET['categoryID'])) {
$_SESSION['postCategory']['categoryID'] = $_GET['categoryID'];
}
$que = "SELECT * FROM `post`";
$res = $con->query($que);
while ($row = $res->fetch_assoc()) {
if ($row['categoryID'] == $_SESSION['postCategory']['categoryID']) {
header("Location:postCategory.php?categoryID=".$_SESSION['postCategory']['categoryID']);
} else {
echo "<script type='text/javascript'>alert('$message');</script>";
header("Location:addpost.php");
}
}
?>
</body>
</html>
答案 0 :(得分:0)
使用javascript重定向到“ addpost.php”:
echo "<script type='text/javascript'>
alert('$message');
window.location.href = 'addpost.php';
</script>";