PHP ->masql 登入 增 刪 改

來源:互聯網
上載者:User

標籤:table   check   mysq   添加   text   let   blog   使用者名稱   action   

登入<form action="chuli.php" method="post"><div>使用者名稱:<input type="text" name="uid" /></div><div>密碼:<input type="password" name="pwd" /></div><div><input type="submit" value="登入" /></div></form>登入處理<?php$uid = $_POST["uid"];$pwd = $_POST["pwd"];//造連線物件$db = new MySQLi("localhost","root","123","mydb");//寫SQL語句//SQL注入攻擊$sql = "select password from login where username=‘{$uid}‘";//執行SQL語句$reslut = $db->query($sql);$n = $reslut->fetch_row();if($uid!="" && $pwd !="" ){    if($n[0]==$pwd)    {        header("location:main.php");    }    else    {        echo "使用者名稱或密碼錯誤!";    }}else{    echo "使用者名稱密碼不可為空";}資料顯示<body><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 info";    //執行SQL語句    $result = $db->query($sql);    //讀資料    $attr = $result->fetch_all();        foreach($attr as $v)    {        echo "<tr>";                $sex = $v[2]?"男":"女";                //根據名族代號查詢名族名稱        $name = NationName($v[3]);                echo "<td>{$v[0]}</td><td>{$v[1]}</td><td>{$sex}</td><td>{$name}</td><td>{$v[4]}</td><td><a href=‘shanchu.php?c={$v[0]}‘ onclick=\"return confirm(‘確定刪除嗎?‘)\">刪除</a></td>";                /*foreach($v as $v1)        {            echo "<td>{$v1}</td>";        }*/                echo "</tr>";    }        //給一個民族代號,返回民族名稱    function NationName($code)    {        //造連線物件        $db = new  MySQLi("localhost","root","123","mydb");        //寫SQL語句        $sql = "select name from nation where code=‘{$code}‘";        //執行SQL語句        $result = $db->query($sql);                $attr = $result->fetch_row();                return $attr[0];    }        ?>        </table><a href="add.php"><input type="button" value="添加資料" /></a></body> 刪除<?php$code = $_GET["c"];//造連線物件$db = new MySQLi("localhost","root","123","mydb");$sql = "delete from info where code=‘{$code}‘";$r = $db->query($sql);if($r){    header("location:main.php");}else{    echo "刪除失敗";}修改<form action="addchuli.php" method="post">    <div>代號:<input type="text" name="code" /></div>    <div>姓名:<input type="text" name="name" /></div>    <div>性別:    <input type="radio" name="sex" value="1" checked="checked" />男    &nbsp;    <input type="radio" name="sex" value="0" />女    </div>    <div>民族:    <select name="nation">        <?php        //造連線物件        $db = new MySQLi("localhost","root","123","mydb");        $sql = "select * from nation";        $result = $db->query($sql);        $attr = $result->fetch_all();                foreach($attr as $v)        {            echo "<option value=‘{$v[0]}‘>{$v[1]}</option>";        }        ?>    </select>    </div>    <div>生日:<input type="text" name="birthday" /></div>        <div><input type="submit" value="添加" /></div></form></body>修改處理<?php$code = $_POST["code"];$name = $_POST["name"];$sex = $_POST["sex"];$nation = $_POST["nation"];$birthday = $_POST["birthday"];//造連線物件$db = new MySQLi("localhost","root","123","mydb");$sql = "insert into info values(‘{$code}‘,‘{$name}‘,{$sex},‘{$nation}‘,‘{$birthday}‘)";$db->query($sql);header("location:main.php"); 

 

PHP ->masql 登入 增 刪 改

相關文章

聯繫我們

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