[英]How can I display something to a user with php in my web app?
I want to be able to show an output to the user when he tries to log in or sign up and he isn't able to.我希望能够在用户尝试登录或注册但无法登录时向他显示 output。 Ideally I want to be able to call a JavaScript
function from a file or at least call prompt()
or something like that.理想情况下,我希望能够从文件中调用JavaScript
function 或者至少调用prompt()
或类似的东西。 The code is the following:代码如下:
<?php
include("../php/functions.php");
include("../php/connect.php");
do{
if(isset($_POST['submit-btn'])) {
$loggedIn = authenticate($conn, $_POST['email'], $_POST['password']);
if($loggedIn === null) {
/**TODO: Do something when the database couldn't be reached */
break;
}
if(!$loggedIn) {
/***TODO: Do something when the password is incorrect*/
break;
}
if($loggedIn)
header("Location: ../html/homepage.html");
}
}while(false)
?>
I get the data from $_POST['*value*']
after the user has submited it and I don't know how to show a, somewhat, presentable error message to he user.在用户提交数据后,我从$_POST['*value*']
获取数据,但我不知道如何向用户显示某种程度上可呈现的错误消息。
Showing an output to the user on an unsuccessful login should be as simple changing your code from this:在登录失败时向用户显示 output 应该很简单,只需将您的代码更改为:
if(!$loggedIn) {
/***TODO: Do something when the password is incorrect*/
break;
}
to this:对此:
if(!$loggedIn) {
echo "<p>Login unsuccessful!</p>";
break;
}
If you want to call a JavaScript function you also can do it with the same approach:如果你想拨打 JavaScript function 你也可以用同样的方法:
if(!$loggedIn) {
echo "<script>function warning() { alert('Wrong password!'); } warning();</script>";
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.