我有两页:HOME和VOTE。我的目标是,当我点击VOTE导航时,它应该提示我,我无法投票(不重新加载页面)。然后,它将重定向/转到HOME页面。
我尝试了这个声明,但它重新加载页面而不是给我提示我想要的。
投票页面:
<?php
$session_id=$_SESSION['std_id'];
$sql= "select * from tbl_student WHERE std_id='$session_id' AND std_status='Unvoted' AND validate ='Unenrolled'";
$query = $con->query($sql);
$count = mysqli_num_rows($query);
if($count==1){
echo "Sorry, You are not enrolled in this semester <br> You are no longer to vote or proceed to Cast Vote. Thank you.";// what codes should I replace for this?
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=home.php">'; // what codes should I replace for this?
}
?>
答案 0 :(得分:0)
您需要更改
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=home.php">'; // what codes should I replace for this?
到
header( 'Location: home.php' );
完整代码:
<?php
$session_id=$_SESSION['std_id'];
$sql= "select * from tbl_student WHERE std_id='$session_id' AND std_status='Unvoted' AND validate ='Unenrolled'";
$query = $con->query($sql);
$count = mysqli_num_rows($query);
if($count==1){
echo "Sorry, You are not enrolled in this semester <br> You are no longer to vote or proceed to Cast Vote. Thank you.";
header( 'Location: home.php' );
}
?>
修改强>
如果您需要显示消息并稍后重定向,则应使用此选项:
<?php
$session_id=$_SESSION['std_id'];
$sql= "select * from tbl_student WHERE std_id='$session_id' AND std_status='Unvoted' AND validate ='Unenrolled'";
$query = $con->query($sql);
$count = mysqli_num_rows($query);
if($count==1) {
echo "Sorry, You are not enrolled in this semester <br> You are no longer to vote or proceed to Cast Vote. Thank you.";
}
?>
<script>setTimeout(function () {
window.location.href = "home.php";
}, 3000);
</script>