conn.php
<?php $conn = mysqli_connect("localhost:3306", "root", "123456","db") or die("連接數據庫服務器失敗!".mysqli_error()); //連接MySQL服務器,選擇數據庫 mysqli_query($conn,"set names utf8"); //設置數據庫編碼格式utf8 ?>
gl.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>管理員界面</title>
</head>
<body>
<div align="center">
<a href="gadd.html">添加商品</a><br>
<a href="del.php">刪除商品</a><br>
<a href="update.php">更改商品</a><br>
<a href="updd.html">更改訂單狀態</a><br>
</div>
</body>
</html>
gadd.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加商品界面</title>
</head>
<body>
<div align="center" >
<form action="gadd.php" method="post">
書名<input type="text" name="name"><br>
價格<input type="text" name="prince"><br>
數量<input type="text"name="number"><br>
<input type="submit" value="確認添加">
</form>
</div>
</body>
</html>
gadd.php
<?php /** * Created by PhpStorm. * User: 田慶輝 * Date: 2020/5/29 * Time: 11:00 */ $name=$_POST['name']; $prince=$_POST['prince']; $number=$_POST['number']; include_once("conn.php"); $sql = "insert into book(name,prince,number) values ('$name','$prince','$number')"; //echo 'sql語句為',$sql; $result = mysqli_query($conn,$sql); //echo $result; if ($result){ echo "添加成功,點擊<a href='gl.html'>這里</a>回到主菜單"; }else{ echo "<script>alert('添加失敗');history.go(-1);</script>"; }
del.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>刪除商品界面</title>
<style type="text/css">
html{font-size:12px;}
fieldset{width:850px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; width:70px; margin-left:10px;}
.left{margin-left:80px;}
.input{width:150px;}
.sousu{margin-left:210px; width:300px}
.sousubutton{margin-left:20px;}
</style>
</head>
<body>
<?php
?>
<fieldset>
<legend><font color="blue">商品刪除</font></legend>
<p>
<input id="sousu" name="sousu" type="text" class="sousu" >
<input type="submit" name="sousubutton" value="搜索" class="sousubutton">
<p/>
<table border="0px"cellspacing="20px" cellpadding="5px">
<?php
include_once("conn.php");
$sql = "select * from book ";
$rs=mysqli_query($conn,$sql);
//$row = mysqli_fetch_array($rs);
while($row = mysqli_fetch_row($rs)){
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td><a href='del2.php?id=$row[0]' >刪除</a></td><td></td></tr>";
}
?>
</table>
</fieldset>
</body>
</html>
del2.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>刪除界面</title>
</head>
<body>
</div>
</body>
</html>
<?php
include_once("conn.php");
$name=$_GET['id'];
echo $name,'商品已經被刪除';
$sql = "delete from book where name = '$name'";
//echo 'sql語句為',$sql;
$result = mysqli_query($conn,$sql);
//echo $result;
if ($result){
echo "點擊<a href='gl.html'>這里</a>回到主菜單";
}else{
echo "<script>alert('刪除失敗');history.go(-1);</script>";
}
update.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>修改商品界面</title>
<style type="text/css">
html{font-size:12px;}
fieldset{width:850px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; width:70px; margin-left:10px;}
.left{margin-left:80px;}
.input{width:150px;}
.sousu{margin-left:210px; width:300px}
.sousubutton{margin-left:20px;}
</style>
</head>
<body>
<?php
?>
<fieldset>
<legend><font color="blue">商品修改</font></legend>
<p>
<input id="sousu" name="sousu" type="text" class="sousu" >
<input type="submit" name="sousubutton" value="搜索" class="sousubutton">
<p/>
<table border="0px"cellspacing="20px" cellpadding="5px">
<?php
include_once("conn.php");
$sql = "select * from book ";
$rs=mysqli_query($conn,$sql);
//$row = mysqli_fetch_array($rs);
while($row = mysqli_fetch_row($rs)){
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td><a href='update2.php?id=$row[0]' >修改</a></td><td></td></tr>";
}
?>
</table>
</fieldset>
</body>
</html>
update.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>修改界面</title>
</head>
<body>
<div align="center">
請輸入修改后的信息
<form action="" method="post">
書名<input type="text" name="name" value=<?php echo $_GET['id']?> ><br><br>
價格<input type="text" name="prince"> <br><br>
數量<input type="text" name="number"><br><br>
<input type="submit" value="確認修改">
</form>
</div>
</body>
</html>
<?php
if($_POST)
{
$name=$_POST['name'];
$prince=$_POST['prince'];
$number=$_POST['number'];
include_once("conn.php");
$sql = "update book set name='$name',prince='$prince',number='$number' where name='$name' ";
//echo 'sql語句為',$sql;
$result = mysqli_query($conn,$sql);
//echo $result;
if ($result){
echo "修改成功點擊<a href='gl.html'>這里</a>回到主菜單";
echo "<script>alert('修改成功');history.go(-2);</script>";
}else{
echo "<script>alert('修改失敗');history.go(-1);</script>";
}
}
updateorder.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>修改訂單狀態界面</title>
<style type="text/css">
html{font-size:12px;}
fieldset{width:850px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; width:70px; margin-left:10px;}
.left{margin-left:80px;}
.input{width:150px;}
.sousu{margin-left:210px; width:300px}
.sousubutton{margin-left:20px;}
</style>
</head>
<body>
<?php
?>
<fieldset>
<legend><font color="blue">訂單修改</font></legend>
<p>
<input id="sousu" name="sousu" type="text" class="sousu" >
<input type="submit" name="sousubutton" value="搜索" class="sousubutton">
<p/>
<table border="0px"cellspacing="20px" cellpadding="5px">
<?php
include_once("conn.php");
$sql = "select * from orderinfo ";
$rs=mysqli_query($conn,$sql);
echo "<tr><td>商品名(書名)</td><td>用戶名</td><td>地址</td><td>電話號碼</td><td>訂單狀態</td><td>操作</td><td></td></tr>";
//$row = mysqli_fetch_array($rs);
while($row = mysqli_fetch_row($rs)){
echo "<tr><td>《$row[3]》</td><td>$row[2]</td><td>$row[1]</td><td>$row[4]</td><td>$row[5]</td><td><a href='updateorder2.php?id=$row[0]' >修改訂單狀態</a></td><td></td></tr>";
}
?>
</table>
</fieldset>
</body>
</html>
updaterorder2.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>修改界面</title>
</head>
<body>
<div align="center">
請輸入修改后的信息
<form action="" method="post">
訂單號<input type="text" name="name" value=<?php echo $_GET['id']?> ><br><br>
訂單狀態<select name="state">
<option value ="未發貨">未發貨</option>
<option value ="已發貨">已發貨</option>
<option value="用戶已經接收貨物">用戶已經接收貨物</option>
</select><br><br>
<input type="submit" value="確認修改">
</form>
</div>
</body>
</html>
<?php
if($_POST)
{
$state=$_POST['state'];
$id=$_POST['name'];
include_once("conn.php");
$sql = "update orderinfo set state='$state' where num=$id ";
//echo 'sql語句為',$sql;
$result = mysqli_query($conn,$sql);
//echo $result;
if ($result){
echo "修改成功點擊<a href='gl.html'>這里</a>回到主菜單";
echo "<script>alert('修改成功');history.go(-2);</script>";
}else{
echo "<script>alert('修改失敗');history.go(-1);</script>";
}
}
addorder.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加訂單界面</title>
</head>
<body>
<div align="center" >
<form action="" method="post">
商品名<input type="text"name="goods"><br>
用戶名<input type="text" name="username"><br>
收貨地址<input type="text" name="address"><br>
電話號碼<input type="text" name="phone"><br>
<input type="submit" value="確認添加">
</form>
</div>
</body>
</html>
<?php
if($_POST) {
$goods=$_POST['goods'];
$username=$_POST['username'];
$address=$_POST['address'];
$phone=$_POST['phone'];
include_once("conn.php");
$sql = "insert into orderinfo(goods,username,address,phone,state) values ('$goods','$username','$address','$phone','未發貨')";
//echo 'sql語句為',$sql;
$result = mysqli_query($conn, $sql);
//echo $result;
if ($result) {
echo "<script>alert('修改成功');history.go(-2);</script>";
} else {
echo "<script>alert('添加失敗');history.go(-1);</script>";
}
}
seeorder.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>查看訂單界面</title>
<style type="text/css">
html{font-size:12px;}
fieldset{width:850px; margin: 0 auto;}
legend{font-weight:bold; font-size:14px;}
label{float:left; width:70px; margin-left:10px;}
.left{margin-left:80px;}
.input{width:150px;}
.sousu{margin-left:210px; width:300px}
.sousubutton{margin-left:20px;}
</style>
</head>
<body>
<?php
?>
<fieldset>
<legend><font color="blue">訂單詳情查看</font></legend>
<p>
<input id="sousu" name="sousu" type="text" class="sousu" >
<input type="submit" name="sousubutton" value="搜索" class="sousubutton">
<p/>
<table border="0px"cellspacing="20px" cellpadding="5px">
<?php
include_once("conn.php");
$sql = "select * from orderinfo ";
$rs=mysqli_query($conn,$sql);
//$row = mysqli_fetch_array($rs);
echo "<tr><td>商品名(書名)</td><td>用戶名</td><td>地址</td><td>電話號碼</td><td>訂單狀態</td><td></td><td></td></tr>";
while($row = mysqli_fetch_row($rs)){
echo "<tr><td>《$row[1]》</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td><td></td><td></td></tr>";
}
?>
</table>
</fieldset>
</body>
</html>





