PHP警报消息 [英] PHP alert message
问题描述
我知道每个人都要说的第一件事是,这已经发布了几百次;然而,我已经尝试了所有不同的方法,人们建议仍然没有运气...我试图得到一个警告消息弹出如果登录失败,但由于某种原因,该消息不想出现。这是我到目前为止:
I know the first thing everyone is going to say is that this has been posted hundreds of times; however, I have tried all the different methods people have suggested with still no luck... I am trying to get an alert message to popup if the login fails but for some reason the message does not want to appear. Here's what I have so far:
if($conn) {
$result=sqlsrv_query($conn, "SELECT * FROM Operator
WHERE Username='{$_POST['login']}'");
$pass=sqlsrv_fetch_array($result);
if($pass["Password"] === $_POST['password']) {
session_start();
$_SESSION['loggedin']=true;
header("Location: home.php");
exit;
}
else {
header("Location: login.php");
echo '<script type="text/javascript">';
echo 'alert("Password Invalid!")';
echo '</script>';
}
}
sqlsrv_close($conn);
php工作正常,但由于某种原因,我无法使javascript工作。任何想法?
The php is working fine but for some reason I can't get the javascript to work. Any ideas?
推荐答案
我想,问题在这里。
header("Location: login.php"); /* Redirect browser */
尝试删除它,或在几秒钟后重定向
try removing it, or make it redirect after a couple of seconds, like this
header( "refresh:5;url=login.php" ); //redirect after 5 seconds
或者提示用户单击进入下一页的对话框。移除标头()tho
or you prompt a dialog for the user to click to go to next page. remove the header() tho
<script type="text/javascript">
<!--
var retVal = confirm("Login FAILED! Do you want to continue ?");
if( retVal == true ){
window.location.href = "login.php";
return true;
}else{
alert("User does not want to continue!");
return false;
}
//-->
</script>
这篇关于PHP警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!