亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我無法獲得登錄表單以正確連接與mySQL數據庫的交互

我無法獲得登錄表單以正確連接與mySQL數據庫的交互

明月笑刀無情 2019-11-20 13:11:33
我想讓用戶使用用戶名和密碼登錄,并且該數據是否與數據庫中的用戶名匹配。當我嘗試時,我沒有收到任何錯誤,但是沒有用。我在Dreamweaver中使用html和php,在phpMyAdmin中使用WAM。我將同時包括表單文檔和隨附的php文檔:loginpage.php <?phpinclude('login.php'); // Includes Login Scriptif(isset($_SESSION['login_user'])){header("location: index.php");}?><table width="15px" border="0"><form form action='login.php' method='POST'><tr><td>Username</td><td><input type="text" name="username" /></td></tr><tr><td>Password</td><td><input type="password" name="password" /></td></tr><tr>  <td><input type="submit" name="submit" value="submit"/></td></tr></form>ogin.php  <html>   <head>    <title>Login</title>  </head>  <body>  <?php     session_start(); // Starting Session    $error=''; // Variable To Store Error Message    if (isset($_POST['submit'])) {    if (empty($_POST['username']) || empty($_POST['password'])) {    $error = "Username or Password is invalid";    }    else    {    // Define $username and $password    $username=$_POST['username'];    $password=$_POST['password'];    // Establishing Connection with Server by passing server_name, user_id   and password as a parameter    $hostname= "localhost";    $database = "boost";    $username = "root";    $password = "";    $localhost = mysqli_connect($hostname, $username, $password, $database);    if(mysqli_connect_errno())    {        die("Connection Failed".mysqli_error());    }    // SQL query to fetch information of registerd users and finds user match.    $sql = "SELECT * FROM `users`";    $query = mysqli_query($localhost,$sql);    if(!$query)    {        die("Query Failed".mysqli_error($localhost));    }    $rows = mysqli_num_rows($query);    if ($rows == 1) {    $_SESSION['login_user']=$username; // Initializing Session    echo "You are now logged on!";    } else {    $error = "Username or Password is invalid";    }    mysqli_close($localhost); // Closing Connection    }    }  ?> </body> </html>
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 507 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號