在Html中嵌入Php [英] Embed Php in Html

查看:103
本文介绍了在Html中嵌入Php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码来检查用户名和密码是否匹配并存在于数据库中,并且我在它下面有一个html文档,它是登录表单。问题在于,如果用户的登录凭证不正确,则会在屏幕顶部打印凭证无效,我希望它在Html中的用户名框上方。请帮助:)


  if($ username == $ dbUserName&& $ password == $ dbPassword){
$ _SESSION ['username'] = $ username;
$ _SESSION ['id'] = $ userId;
header('Location:user.php');
} else {
echo< b>< i>凭证无效< / i>< b>;


解决方案

将错误信息保存到

您的php代码:

  if($ username == $ dbUserName&& $ password == $ dbPassword){
$ _SESSION ['username'] = $ username;
$ _SESSION ['id'] = $ userId;
header('Location:user.php');
} else {
$ login_error =< b>< i>凭证无效< / i>< b>;
}

在您的html部分中:

 < div id =log_err> <?= $ login_error; ?> < / DIV> 
< input type =textname =username>


i have a code which checks if username and password match and exist in database, and i got an html document below it, which is the login form. The problem is if the user's login credentials are incorrect the statement Invalid credentials gets printed at top of the screen, I want it above the Username box in Html. Please help :)

if($username == $dbUserName && $password == $dbPassword) {
    $_SESSION['username'] = $username;
    $_SESSION['id'] = $userId;
    header('Location: user.php');
} else {
    echo "<b><i>Invalid credentials</i><b>";
}

解决方案

Save your error message into a variable then print it wherever you want.

your php code:

if($username == $dbUserName && $password == $dbPassword) {
    $_SESSION['username'] = $username;
    $_SESSION['id'] = $userId;
    header('Location: user.php');
} else {
    $login_error =  "<b><i>Invalid credentials</i><b>";
}

in your html part:

<div id="log_err"> <?= $login_error; ?> </div>
<input type="text" name="username">

这篇关于在Html中嵌入Php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆