簡體   English   中英

創建登錄表單錯誤消息(php,css,html)

[英]Creating a login form error message (php,css,html)

我試圖創建錯誤消息/試圖使我的css框在按下登錄按鈕后沒有輸入時變成紅色。

我的登錄頁面

   <?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是..

}

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;
}

用戶名,密碼登錄按鈕都在登錄頁面類和表單類中。 關於我將如何做自己想做的任何建議。 我已經嘗試了好幾個小時,但找不到任何可以幫助我的方式。

任何幫助表示贊賞。 - 非常感謝

如果您想通過php進行此操作,則可以讓您的帖子添加一個類到表單輸入中,例如:

PHP

<?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

.no-content-error
{
    border: 1px solid red;
}

HTML

<form>
    <input type="text" class="<?php echo $error; ?>"/>
    ///The rest of your html
</form>

只需以完全相同的方式將html用於表單即可。 以相同的方式為其他任何空輸入添加另一個錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM