欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php+MySQL實(shí)現(xiàn)登錄時(shí)驗(yàn)證登錄名和密碼是否正確

 更新時(shí)間:2016年05月10日 14:19:03   作者:Run_the_youth  
本文實(shí)例實(shí)現(xiàn)登錄時(shí)去數(shù)據(jù)庫校驗(yàn)用戶輸入的登錄名和密碼是否正確,這篇文章主要介紹了php+MySQL實(shí)現(xiàn)登錄時(shí)校驗(yàn)登錄名和密碼是否正確,感興趣的小伙伴們可以參考一下

直入主題,先看php校驗(yàn)登錄名和密碼是否正確的代碼:

<?php
 $servername = "服務(wù)器名";
 $username = "賬戶名";
 $password = "密碼";
 $dbname = "數(shù)據(jù)庫名";
?>
<?php
 // Session需要先啟動。
 session_start();
 //判斷uname和pwd是否賦值
 if(isset($_POST['uname']) && isset($_POST['pwd'])){
 $name = $_POST['uname'];
 $pwd = $_POST['pwd'];
 //連接數(shù)據(jù)庫
 $conn = new mysqli($servername, $username, $password, $dbname);
 if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
 }
 //驗(yàn)證內(nèi)容是否與數(shù)據(jù)庫的記錄吻合。
 $sql = "SELECT * FROM test_students_all WHERE (student_name='$name') AND (password='$pwd')";
 //執(zhí)行上面的sql語句并將結(jié)果集賦給result。
 $result = $conn->query($sql);
 //判斷結(jié)果集的記錄數(shù)是否大于0
 if ($result->num_rows > 0) {
  $_SESSION['user_account'] = $name;
  // 輸出每行數(shù)據(jù)
  while($row = $result->fetch_assoc()) {
  echo '<p>' . $row['student_nbr'] . '<br/>' . $row['student_name'] . '(' . $row['sex'] . ')' . '<br/>' . $row['class'] . '<br/>' . $row['major'].'</p>';
  // <p><img src="student_images/CLASS/STUDENT_NBR.jpg" /></p>
  echo '<p><img src="student_images/' . $row['class'] . '/' . $row['student_nbr'] . '.jpg" /></p>';
  }
 } else {
  echo "沒有您要的信息";
 }
 $conn->close(); 
 }
?>
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>登錄校驗(yàn)</title>
</head>
<body>
 <p>
 <?php
  // isset(xx) 測試xx是否設(shè)置了
  if(isset($_SESSION['user_account'])){
  echo '你好,' . $_SESSION['user_account'];
  }
  else{
  echo '游客';
  }
  //$conn->close();
 ?>
 </p>
 <form method="POST">
 <input type="text" name="uname" placeholder="用戶名" />
 <br />
 <input type="password" name="pwd" placeholder="密碼" />
 <br />
 <input type="submit">
 </form>
</body>
</html>

效果圖:

以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論