1 / 8

PHP and MySQL

PHP and MySQL. Chin-Yi Tsai cyt@pmlab.iecs.fcu.edu.tw http://140.134.26.25/~cyt. Example. account.php insert.php update.php delete.php search.php. insert into account values($new_id, '$name'). update account set name = '$name' where id =$id. delete from account where id =$id.

dafydd
Download Presentation

PHP and MySQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP and MySQL Chin-Yi Tsai cyt@pmlab.iecs.fcu.edu.tw http://140.134.26.25/~cyt

  2. Example • account.php • insert.php • update.php • delete.php • search.php insert into account values($new_id, '$name') update account set name = '$name' where id =$id delete from account where id =$id select * from account where name = '$name'

  3. <?php $link = mysql_connect("localhost", “root", “ "); $select = mysql_select_db("test_db", $link); $sql_select = "select * from account"; $result = mysql_query($sql_select); ?> <html> <title>PHP and Mysql Example</title> <body> <center> <table border =1> <tr> <td>編號 <td>姓名 <?php while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row[0]; echo "<td>" . $row[1]; } mysql_free_result($result); ?> account.php

  4. </table> <hr> <form action="insert.php" method="post"> 姓名<input type=text name=name size=20> <input type=submit value="新增"> </form> <hr> <form action="update.php" method="post"> 編號<input type=text name=id size=5> 姓名<input type=text name=name size=20> <input type=submit value="修改"> </form> <hr> <form action="delete.php" method="post"> 編號<input type=text name=id size=5> <input type=submit value="刪除"> </form> <hr> <form action="search.php" method="post"> 姓名<input type=text name=name size=20> <input type=submit value="搜尋"> </form> </center> </body> </html> account.php

  5. insert.php <?php $link = mysql_connect("localhost", "root", " "); $select = mysql_select_db("test_db", $link); $id = $_POST['id']; $name = $_POST['name']; $sql_update = "update account set name = '$name' where id =$id"; mysql_query($sql_update); header("Location: http://leo.pmlab.iecs.fcu.edu.tw/PHP_example/PHP_cyt/account.php"); ?>

  6. update.php <?php $link = mysql_connect("localhost", "root", " "); $select = mysql_select_db("test_db", $link); $id = $_POST['id']; $name = $_POST['name']; $sql_update = "update account set name = '$name' where id =$id"; mysql_query($sql_update); header("Location: http://127.0.0.1/account.php"); ?>

  7. delete.php <?php $link =mysql_connect("localhost", "root", " "); $select = mysql_select_db("test_db", $link); $id = $_POST['id']; $sql_delete = "delete from account where id =$id"; mysql_query($sql_delete); header("Location: http://127.0.0.1/account.php"); ?>

  8. search.php <?php $link = mysql_connect("localhost", "root", " "); $select = mysql_select_db("test_db", $link); $name = $_POST['name']; $sql_search = "select * from account where name = '$name'"; $result = mysql_query($sql_search); ?> <html> <body> <?php $row = mysql_fetch_array($result); echo "搜尋結果<br>"; echo "編號:".$row[0]."<br>"; echo "姓名:".$row[1]."<br>"; ?> <br> <a href="account.php">返回</a> </body> </html>

More Related