首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >创建登录表单错误消息(php、css、html)

创建登录表单错误消息(php、css、html)
EN

Stack Overflow用户
提问于 2018-10-21 22:35:04
回答 1查看 3K关注 0票数 0

我正在尝试创建错误消息/尝试使我的css框在按下登录按钮后没有输入时变为红色。

代码语言:javascript
复制
   <?php
    session_start();    //starting the db session



    $db = mysqli_connect("localhost", "root", "", "authentication");     // database connection selections, aswell as setting a variable.  db = database

    if (isset($_POST['login_btn'])) {
        $username = mysqli_real_escape_string($db, $_POST['username']);       // this is giving the login button a command, defining that the variables $password and username are the box contents
        $password = mysqli_real_escape_string($db, $_POST['password']);

        $password = md5($password); //sha256 is a type of hash, making the password more secure
        $sql = "SELECT * FROM users WHERE username='$username' AND password='$password' ";
        $result = mysqli_query($db, $sql);



        if (mysqli_num_rows($result) == 1) {
            $_SESSION['message'] = "Succesfully logged in";  //the, if login details are correct you will re-directed to the home.php page, else message: unsuccessfully logged in
            $_SESSION['username'] = $username;                      //validation if user name = db username
            header("location: home.php");  //location
        }else{
            // turn the box's RED hear as error ???
        }
    }



?>

这是我登录页面的php的一部分,正如你所看到的,我想把框的颜色设为红色。

到目前为止,我对这个页面的css是..

代码语言:javascript
复制
}

body {
    background-color: #FF9615;
}



.login-page {
  width: 360px;
  padding: 8% 0 0;
  margin: auto;
}

.form {
  position: relative;
  z-index: 1;
  background: #FFFFFF;
  max-width: 360px;
  margin: 0 auto 100px;
  padding: 45px;
  text-align: center;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 5px 5px 0 rgba(0, 0, 0, 0.24);
}
.form input {
  outline: 0;
  background: #f2f2f2;
  width: 100%;
  border: 0;
  margin: 0 0 15px;
  padding: 15px;
  box-sizing: border-box;
  font-size: 14px;
}

用户名、密码登录按钮都在登录页面类和表单类中。任何关于我将如何去做我想做的事情的建议。我试着找了几个小时,但找不到任何帮助我想要的方式。

任何帮助都是非常感谢的。-非常感谢

EN

回答 1

Stack Overflow用户

发布于 2018-10-21 22:49:59

如果你想通过php做到这一点,你可以让你的帖子在你的表单输入中添加一个类,类似于:

PHP

代码语言:javascript
复制
<?php
session_start();    //starting the db session

$error = ""; //Set the class to empty on page load

$db = mysqli_connect("localhost", "root", "", "authentication");     // database 
connection selections, aswell as setting a variable.  db = database

if (isset($_POST['login_btn'])) {
    $username = mysqli_real_escape_string($db, $_POST['username']);       // this is giving the login button a command, defining that the variables $password and username are the box contents
    $password = mysqli_real_escape_string($db, $_POST['password']);

    $password = md5($password); //sha256 is a type of hash, making the password more secure
    $sql = "SELECT * FROM users WHERE username='$username' AND password='$password' ";
    $result = mysqli_query($db, $sql);

    if ($username == "")
    {
        $error = "no-content-error";
    } 
    ///The rest of your php code
?>

CSS

代码语言:javascript
复制
.no-content-error
{
    border: 1px solid red;
}

HTML

代码语言:javascript
复制
<form>
    <input type="text" class="<?php echo $error; ?>"/>
    ///The rest of your html
</form>

只需以完全相同的方式使用表单的html即可。以同样的方式为任何其他空输入添加另一个错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52916401

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档