php處理登入、添加資料、刪除資料和修改資料

來源:互聯網
上載者:User

標籤:bsp   log   test   color   ref   ext   最佳化   confirm   result   

  php 處理登入 :需要先建一個登入的頁面,用form表單就可以很輕鬆的完成,(這裡的樣本是我根據資料庫現成的表做的 是一個teacher表格 根據老師的工號和姓名登入的)

<form action="chuli.php" method="post">  <div>     工號: <input type="text" name="tno"/>  </div>    <div>        姓名:<input type="text" name="tname"/>    </div>    <div><input type="submit" value="登入"/></div></form>

完成後跳轉到處理頁面

<?php$tno=$_POST["tno"];$tname=$_POST["tname"];//串連資料庫$db=new mysqli("localhost","root","root","test");//寫查詢代碼$sql="select tname from teacher where tno=‘{$tno}‘";//執行代碼 有返回集$result=$db->query($sql);$a=$result->fetch_row();//判斷姓名不能是空 if(!empty($tname)&&$a[0]=$tname){    header("location:main.php");}else{    echo"登入失敗";}?>

 

即 串連資料庫後 尋找登入名稱和密碼 然後根據所尋找到的登入即可,登入成功後返回首頁面就可以了。

 php添加資料: 在首頁面上面 我們建立一個表格 讓資料庫的資料以表格的資料呈現,

<table cellpadding="0" cellspacing="0" border="1" width="100%"><tr>    <td>工號</td>    <td>姓名</td>    <td>性別</td>    <td>生日</td>    <td>層級</td>    <td>任課</td>    <td>操作</td></tr>    <?php$db=new mysqli("localhost","root","root","test");$sql="select * from teacher";$result=$db->query($sql);if($result){    while($arr=$result->fetch_row())    {        $arr[2]?"男":"女";  //最佳化網頁,如果輸入1 就是返回男  如果輸入0  返回的就是女        echo"<tr>    <td>{$arr[0]}</td>    <td>{$arr[1]}</td>    <td>{$arr[2]}</td>    <td>{$arr[3]}</td>    <td>{$arr[4]}</td>    <td>{$arr[5]}</td>    <td><a onclick=\"return confirm(‘確定要刪除嗎‘)\"  href=‘shanchu.php?tno={$arr[0]}‘>刪除</a></td></tr>";    }}?></table>

 

在表格下面用<a>添加資料</a>

<a  href="tianjia.php">添加資料</a>

標籤,然後點擊添加資料跳轉到添加資料的頁面, 和登入頁面是一樣的 都是採用的form表單,很簡單的把需要的呈現出來

php刪除資料: 在首頁面的表格中添加一列,(已經在上面的代碼中展現出來了) 用<a>刪除</a>標籤關聯到刪除頁面,刪除頁面同樣採用form表單

php修改資料:相比以上的處理要麻煩一些,是建立在添加資料和刪除資料的基礎上的,其他的和刪除資料的方法是差不多的,

 

php處理登入、添加資料、刪除資料和修改資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.