php登錄頁面:
<h1>登錄界面</h1> <form action="dengluchuli.php" method="post"> 用戶名:<input type="text" name="uid"/> 密碼:<input type="text" name="pwd"/> <input type="submit" value="登錄" /> </form>
其中 dengluchuli.php在規定路徑下。
登錄跳轉頁面:
<?php $yonghuming = $_POST["uid"]; $mima = $_POST["pwd"]; $db = new mysqli("localhost","root","","12345"); $sql = "select password from login where username='{$yonghuming}'"; $result = $db->query($sql); $atter = $result->fetch_row(); if($atter[0]==$mima && !empty($mima)) { header("location:xinxi.php"); } else { echo "用戶名或密碼錯誤"; } ?>
此頁面用於登錄界面登錄成功后通過用戶名找到相應的數據。
登錄主界面:
<?php $de = new mysqli("localhost","root","","12345"); $e="select * from info"; $result = $de->query($e); $atter = $result->fetch_all(); echo "<table border=1>"; echo "<tr> <td>代號</td> <td>姓名</td> <td>性別</td> <td>民族</td> <td>出生日期</td> <td>操作</td> </tr> "; for($i=0;$i<count($atter);$i++) { echo "<tr>"; for($j=0;$j<count($atter[$i]);$j++) { if($j==4) { echo "<td>".$atter[$i][$j]."</td> <td><a href='shanchu.php?code={$atter[$i][1]}' onclick=\"return confirm('確定刪除?')\"> 刪除</a></td>"; } else { echo "<td>".$atter[$i][$j]."</td>"; } } echo "</tr>"; } echo " </table>"; echo "<a href='tianjia.php'>添加數據</a>" ?>
添加數據(tianji.php):
<h1>添加數據</h1> <form action="zeng.php" method="post"> 代號:<input type="text" name="daihao" /> <br /> 姓名:<input type="text" name="xinming" /><br /> 性別:<input type="text" name="xinbie" /><br /> 民族:<input type="text" name="minzu" /><br /> 生日:<input type="text" name="shengri" /><br /> <input type="submit" value="提交"/> </form>
zeng.php :
<?php $code = $_POST["daihao"]; $name = $_POST["xinming"]; $sex = $_POST["xinbie"]; $nation = $_POST["minzu"]; $birthday = $_POST["shengri"]; $db = new mysqli("localhost","root","","12345"); $sql = "insert into info values('{$code}','{$name}','{$sex}','{$nation}','{$birthday}')"; $r = $db->query($sql); if($r) { header("location:xinxi.php"); } else { echo "添加失敗"; } ?>
添加成功:
shanchu.php
<?php $name = $_GET["code"]; $db = new mysqli("localhost","root","","12345"); $sql = "delete from info where name='{$name}'"; $result = $db->query($sql); if($result) { header("location:xinxi.php"); } else { echo "刪除失敗"; } ?>
修改數據:
在xinxi.php文件中插入代碼:
<a href='xiugai.php?code={$atter[$i][1]}'>修改</a>
相同路徑下新建xiugai.php
<?php $name = $_GET["code"]; $db = new mysqli("localhost","root","","12345"); $sql = "select * from info where name='{$name}'"; $r = $db->query($sql); $atter = $r->fetch_row(); ?> <h1>修改</h1> <form action="xiugaichuli.php" method="post"> <input type="hidden" name="daihao" value="<?php echo $atter[0]; ?>" /> <br /> 姓名: <input type="text" name="xinming" value="<?php echo $atter[1]; ?>"/> <br /> 性別: <input type="text" name="xinbie" value="<?php echo $atter[2]; ?>"/> <br /> 民族: <input type="text" name="minzu" value="<?php echo $atter[3]; ?>"/> <br /> 生日: <input type="text" name="shengri" value="<?php echo $atter[4]; ?>"/> <br /> <input type="submit" value="修改" /> </form>
相同路徑下新建xiugaichuli.php
<?php $code = $_POST["daihao"]; $name = $_POST["xinming"]; $sex = $_POST["xinbie"]; $nation = $_POST["minzu"]; $birthday = $_POST["shengri"]; $db = new mysqli("localhost","root","","12345"); $sql = "update info set name='{$name}',sex={$sex},nation='{$nation}',birthday='{$birthday}' where code='{$code}'"; $r = $db->query($sql); if($r) { header("location:xinxi.php"); } else { echo "修改失敗"; } ?>
點擊修改其中一條數據:
修改成功。