php登录注册页面及加载
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>无标题文档</title>
6 </head>
7
8 <body>
9 <h1>水果信息表</h1>
10 <table width="100%" border="1" cellpadding="0" cellpadding="0">
11 <tr>
12 <td>代号</td>
13 <td>名称</td>
14 <td>价格</td>
15 <td>产地</td>
16 <td>库存</td>
17
18 </tr>
19
20 <?php
21 //1.造链接对象
22 $db = new MySQLi("localhost","root","511108","text");
23 //2.写SQL语句
24 $sql = "select*from fruit";
25 //3.执行
26 $result = $db->query($sql);
27 //4.读取数据
28 $attr = $result->fetch_all();
29 foreach($attr as $v)
30 {
31 echo"<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td></tr>";
32 }
39
40 ?>
45 下图1是调取本地数据库表的全部信息
图1
1 删除一条数据并且点击删除的时候有提示是否删除,删除加个点击事件,先执行,点击提示
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <title>无标题文档</title>
7 </head>
8
9 <body>
10 <h1>水果信息表</h1>
11 <table width="100%" border="1" cellpadding="0" cellpadding="0">
12 <tr>
13 <td>代号</td>
14 <td>名称</td>
15 <td>价格</td>
16 <td>产地</td>
17 <td>库存</td>
18 <td>删除</td>
19 </tr>
20
21 <?php
22 //1.造链接对象
23 $db = new MySQLi("localhost","root","511108","text");
24 //2.写SQL语句
25 $sql = "select*from fruit";
26 //3.执行
27 $result = $db->query($sql);
28 //4.读取数据(有两种方法)
29 //1.方法
30 /*$attr = $result->fetch_all();
31 foreach($attr as $v)
32 {
33 echo"<tr><td>{$v[0]}</td><td>{$v[1]}</td><td>{$v[2]}</td><td>{$v[3]}</td><td>{$v[4]}</td></tr>";
34
35 }*/
36 //2.方法
37 while($attr = $result->fetch_row())
38 {
39 echo "<tr><td>{$attr[0]}</td><td>{$attr[1]}</td><td>{$attr[2]}</td><td>{$attr[3]}</td><td>{$attr[4]}</td><td>
40 <a href='shanchu.php?code={$attr[0]}'onclick=\"return confirm('确定删除吗')\">删除
41 </a>
42 </td></tr>";
43
44 }
45
46
47 ?>
48 </table>
49
50
51 </body>
52 </html>
下图2是添加删除并且给删除加超链接
图2
对苹果信息表做里内容做删除如图1。并且按删除给出一个提示如图2。下图3是点击确定以后的结果图1
1 <?php 2 $code = $_GET["code"]; 3 //1.造链接对象 4 $db = new MySQLi("localhost","root","511108","text"); 5 //2.写SQL语句 6 $sql = "delete from fruit where ids='{$code}'";//fruit表格名。ids表格里的主键 7 //3.执行 8 $r = $db->query($sql); 9 if($r) 10 { 11 header("location:pingguoxinxi.php");//删除完成后,跳转到location:pingguoxinxi.php网页,等于从新刷新 12 } 13 else 14 { 15 echo"删除失败!"; 16 }
图2
下图3
添加水果或商品如下
//在pingguoxinxi.php里面做个添加数据的链接如下图1,图2,图3,图4。
图1
往水果表里添加水果数据图2
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>无标题文档</title> 6 </head> 7 8 <body> 9 <h1>添加水果</h1> 10 <form action="tianjiashuiguoshuju.php" method="post"> 11 <div>代号:<input type="text" name="ids" /></div> 12 <div>名称:<input type="text" name="name" /></div> 13 <div>价格:<input type="text" name="price" /></div> 14 <div>产地:<input type="text" name="chandi" /></div> 15 <div>库存:<input type="text" name="numbers" /></div> 16 <div><input type="submit" value="添加" /></div> 17 18 </form> 19 20 </body> 21 </html>
1 <?php
2 $ids = $_POST["ids"];
3 $name = $_POST["name"];
4 $price = $_POST["price"];
5 $chandi = $_POST["chandi"];
6 $numbers = $_POST["numbers"];
7 //1ps造链接对象
8 $db = new MySQLi("localhost","root","511108","text");
9 //2.写SQL语句
10 $sql = "insert into fruit values('{$ids}','{$name}',{$price},'{$chandi}',{$numbers},'')";
11
12 //执行
13 $r = $db->query($sql);
14
15 if($r)
16 {
17 header("location:pingguoxinxi.php");
18 }
19 else
20 {
21 echo "添加失败!";
22 }
图3
图4
图4

浙公网安备 33010602011771号