PHP MYSQL實現登陸和模糊查詢兩大功能,mysql模糊查詢_PHP教程

來源:互聯網
上載者:User

PHP MYSQL實現登陸和模糊查詢兩大功能,mysql模糊查詢


本文使用的軟體版本如下:PHP版本 5.5.12;MYSQL版本 5.6.17;Apache 2.4.9 用的wampserver
一、PHPMYSQL實現登陸
一共含有兩個檔案:login.phplogincheck.php;
表單代碼:


幕後處理代碼:

<?php     if(isset($_POST["submit"])&& $_POST["submit"] == "登陸")     {          $user= $_POST["username"];          $psw= $_POST["password"];          if($user== "" || $psw == "")          {              echo"";          }          else          {              $link= mysqli_connect('localhost', 'sa', '123456','account');//連結資料庫              mysqli_select_db($link,"account");              mysqli_query($link,'setname utf8');              $sql= "selectuser from zhanghu where user = '$_POST[username]'";              $result=mysqli_query($link,$sql)or die("Failed".mysql_error());              if($num=mysqli_num_rows($result))              {                   $row= mysqli_fetch_array($result);    //將資料以索引方式儲存在數組中                   echo"welcome ";                   echo$row[0];              }              else              {                   echo"";              }          }     }     else     {          echo"";     } ?>

Account資料庫內容:

二、PHPMYSQL實現模糊查詢

查詢資料庫(只給PHP的代碼):

<?php     $mysqli=newmysqli();                  $mysqli->connect("localhost","sa", "123456");     if(mysqli_connect_errno()) {          printf("Failllllll:%s\n", mysqli_connect_error());          exit();     }     $mysqli->select_db("booklib");       $mysqli->query("SETNAMES utf8");        $rsbooks= $mysqli->query("select * from books where Name like'%$_POST[bookname]%'");  $row_rsbooks = $rsbooks->fetch_assoc();  $totalRows_rsbooks = $rsbooks->num_rows;    ?> Totel<?php echo $totalRows_rsbooks ?>books;
  <?php do { ?> 
    <?php } while ($row_rsbooks = $rsbooks->fetch_assoc()); ?>
  
Name ISBN Store Do
<?php echo $row_rsbooks['Name']; ?> <?php echo $row_rsbooks['ISBN']; ?> <?php echo $row_rsbooks['Store']; ?> rent
<?php $rsbooks->close(); $mysqli->close();?>

資料庫表的內容如下:

查詢:

結果:

以上就是本文的全部內容,希望對大家學習php程式設計有所協助。

您可能感興趣的文章:

  • 兩大步驟教您開啟MySQL 資料庫遠程登陸帳號的方法
  • MySQL單表多關鍵字模糊查詢的實現方法
  • PHP+MYSQL會員系統的登陸即許可權判斷實現代碼
  • 一個簡單的網頁密碼登陸php代碼
  • mysql增加新使用者無法登陸解決方案
  • MySql like模糊查詢萬用字元使用詳細介紹
  • PHP登陸後跳轉到登陸前頁面實現思路及代碼
  • php中session退出登陸問題
  • mysql中模糊查詢的四種用法介紹
  • thinkphp實現like模糊查詢執行個體

http://www.bkjia.com/PHPjc/1099081.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1099081.htmlTechArticlePHP MYSQL實現登陸和模糊查詢兩大功能,mysql模糊查詢 本文使用的軟體版本如下:PHP版本 5.5.12;MYSQL版本 5.6.17;Apache 2.4.9 用的wampserver 一、...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.