<meta charset="UTF-8">
<?php
$link=mysqli_connect("localhost:3306","root","root","supermarket");
if(!$link) {
echo "连接失败的原因是:" . mysqli_connect_error();
}
mysqli_query($link,"set names utf8");
$sql="select * from goods";
$a=mysqli_query($link,$sql);
while($res=mysqli_fetch_assoc($a)){
$arr[]=$res;
}
//删除
<meta charset="UTF-8">
<?php
$link=mysqli_connect("localhost:3306","root","root","supermarket");
if(!$link) {
echo "连接失败的原因是:" . mysqli_connect_error();
}
mysqli_query($link,"set names utf8");
$id=isset($_GET['id'])?trim($_GET['id']):'';
if(empty($id)) die("要删除的数据没有传过来");
$sql="delete from goods where goods_id in($id)";
$a=mysqli_query($link,$sql);
if($a){
echo "删除成功";
header("location:a.php");
}
else{
echo "删除失败";
header("location:a.php");
}
//添加
<?php
$date=isset($_POST['date'])?trim($_POST['date']):'';
$ge=isset($_POST['ge'])?trim($_POST['ge']):'';
$shu=isset($_POST['shu'])?trim($_POST['shu']):'';
if(empty($date)) die("日期不能为空");
if(empty($ge)) die("价格不能为空");
if(empty($shu)) die("数量不能为空");
$link=mysqli_connect("localhost:3306","root","root","supermarket");
if(!$link) {
echo "连接失败的原因是:" . mysqli_connect_error();
}
mysqli_query($link,"set names utf8");
$sql="insert into goods(goods_id,goods_date,goods_price,goods_num) values(null,'".$date."','".$ge."','".$shu."')";
//根据需求改字段
$a=mysqli_query($link,$sql);
if($a){
echo "添加成功";
header("location:xing.html");
}else{
echo "添加失败";
header("location:xing.html");
}
?>
//修改
<meta charset="UTF-8">
<?php
$link=mysqli_connect("localhost:3306","root","root","yuekao");
if(!$link) echo "链接失败的原因是:" . mysqli_connect_error();
mysqli_query($link,"set names utf8");
$xm=isset($_POST['xm'])?trim($_POST['xm']):'';
$q=isset($_POST['q'])?trim($_POST['q']):'';
$time=isset($_POST['time'])?trim($_POST['time']):'';
$chang=isset($_POST['chang'])?trim($_POST['chang']):'';
$shi=isset($_POST['shi'])?trim($_POST['shi']):'';
$id=isset($_POST['id'])?trim($_POST['id']):'';//接值
if(empty($xm)) die("姓名不能为空");
if(empty($id)) die("id不能为空");
if(empty($time)) die("时间不能为空");
if(empty($chang)) die("场地不能为空");
if(empty($shi)) die("注意事项不能为空");
$time=time();
$sql="update bisai set name='$xm',time='$time',address='$chang',zhu='$shi' where id='$id'";//根据需求更改
$a=mysqli_query($link,$sql);
if($a){
echo "修改成功";
header("location:zeng.php");
}else{
echo "修改失败";
header("location:zeng.php");
}
?>