標籤:http div xmlns onclick 水果 ber header each cin
1.使用者操作頁面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><body><h1>水果資訊表</h1><table width="100%" border="1" cellpadding="0" cellspacing="0" > <tr> <td>代號</td> <td>名稱</td> <td>價格</td> <td>產地</td> <td>庫存</td> <td>操作</td> </tr> <?php //造連線物件 $db = new MySQLi("localhost","root","123","mydb"); //寫SQL語句 $sql = "select * from fruit"; //執行 $result = $db->query($sql); //取資料 /*$attr = $result->fetch_all(); foreach($attr as $v) { echo "<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td></tr>"; }*/ while($attr = $result->fetch_row()) { echo "<tr><td>{$attr[0]}</td><td>{$attr[1]}</td><td>{$attr[2]}</td><td>{$attr[3]}</td><td>{$attr[4]}</td><td> <a href=‘shanchu.php?code={$attr[0]}‘ onclick=\"return confirm(‘確定刪除麼‘)\"> 刪除 </a> </td></tr>"; } ?> </table><a href="add.php">添加資料</a></body><script type="text/javascript"></script></html>
2.添加資料頁面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title></head><body><h1>添加水果</h1><form action="addchuli.php" method="post"><div>代號:<input type="text" name="ids" /></div><div>名稱:<input type="text" name="name" /></div><div>價格:<input type="text" name="price" /></div><div>產地:<input type="text" name="chandi" /></div><div>庫存:<input type="text" name="numbers" /></div><div><input type="submit" value="添加" /></div></form></body></html>
3.刪除處理頁面
<?php$code = $_GET["code"];//造連線物件$db = new MySQLi("localhost","root","123","mydb");//寫SQL語句$sql = "delete from fruit where ids=‘{$code}‘";//執行$r = $db->query($sql);if($r){ header("location:main.php");}else{ echo "刪除失敗!";}
4.添加處理頁面
<?php$ids = $_POST["ids"];$name = $_POST["name"];$price = $_POST["price"];$chandi = $_POST["chandi"];$numbers = $_POST["numbers"];//造連線物件$db = new MySQLi("localhost","root","123","mydb");//寫SQL語句$sql = "insert into fruit values(‘{$ids}‘,‘{$name}‘,{$price},‘{$chandi}‘,{$numbers},‘‘)";//執行$r = $db->query($sql);if($r){ header("location:main.php");}else{ echo "添加失敗!";}
PHP資料庫頁面增刪查