PHP資料庫頁面增刪查

來源:互聯網
上載者:User

標籤: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資料庫頁面增刪查

相關文章

聯繫我們

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