PHP修改与删除

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>

</head>

<body>
<div style="height:50px"></div>

<table class="table table-hover">
<thead>
<tr>
<th>代号</th>
<th>名称</th>
<th>单价</th>
<th>产地</th>
<th>库存</th>
<th>操作</th>
</tr>
</thead>
<tbody>

<?php

$db = new MySQLi("localhost","root","","lian");
$sql = "select * from fruit";
$result = $db->query($sql);
$arr = $result->fetch_all();
foreach($arr as $v){
echo "<tr>
<td>{$v[0]}</td>
<td>{$v[1]}</td>
<td>{$v[2]}</td>
<td>{$v[3]}</td>
<td>{$v[4]}</td>
<td>
<a href='shanchu.php?code={$v[0]}' οnclick=\"return confirm('确定删除么?')\"><button type='button' class='btn btn-primary btn-xs'>删除</button></a>
<a href='xiugai.php?code={$v[0]}' οnclick=\"return confirm('确定修改么?')\"><button type='button' class='btn btn-primary btn-xs'>修改</button></a>
</td>
</tr>";
}
?>

</tbody>
</table>

</body>
</html>

  修改页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script src="../bootstrap/js/jquery-1.11.2.min.js"></script>
<script src="../bootstrap/js/bootstrap.min.js"></script>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<style type="text/css">
*{ margin:0px auto; padding:0px}
.input-group{ margin-top:10px}
.queding{ margin-top:20px; margin-left:260px}
</style>
</head>

<body>
<div style="height:50px"></div>

<?php
$code = $_GET["code"];
$db = new MySQLi("localhost","root","123","mydb");
$sql = "select * from fruit where ids='{$code}'";
$result = $db->query($sql);
$arr = $result->fetch_row();
?>

<form action="xiugai.php" method="post">
<div class="panel panel-default" style="max-width:600px">
<div class="panel-heading">
修改数据
</div>
<div class="panel-body">
<div class="input-group">
<span class="input-group-addon">代号</span>
<input type="text" readonly="readonly" class="form-control" placeholder="请输入代号" name="code" value="<?php echo $arr[0] ?>">
</div>
<div class="input-group">
<span class="input-group-addon">名称</span>
<input type="text" class="form-control" placeholder="请输入名称" name="name" value="<?php echo $arr[1] ?>">
</div>
<div class="input-group">
<span class="input-group-addon">单价</span>
<input type="text" class="form-control" placeholder="请输入单价" name="price" value="<?php echo $arr[2] ?>">
</div>
<div class="input-group">
<span class="input-group-addon">产地</span>
<input type="text" class="form-control" placeholder="请输入产地" name="chandi" value="<?php echo $arr[3] ?>">
</div>
<div class="input-group">
<span class="input-group-addon">库存</span>
<input type="text" class="form-control" placeholder="请输入库存" name="kucun" value="<?php echo $arr[4] ?>">
</div>

<button type="submit" class="btn btn-primary queding">确定</button>

</div>
</div>


</form>
</body>
</html>

 修改处理页面

<?php
$code = $_POST["code"];
$name = $_POST["name"];
$price = $_POST["price"];
$chandi = $_POST["chandi"];
$kucun = $_POST["kucun"];

$db = new MySQLi("localhost","root","","lian");
$sql = "update fruit set name='{$name}',price={$price},source='{$chandi}',numbers={$kucun} where ids='{$code}'";

if($db->query($sql)){
header("location:test.php");
}else{
echo "error";
}

  删除页面

<?php
$code = $_POST["code"];
$name = $_POST["name"];
$price = $_POST["price"];
$chandi = $_POST["chandi"];
$kucun = $_POST["kucun"];

$db = new MySQLi("localhost","root","123","mydb");
$sql = "update fruit set name='{$name}',price={$price},source='{$chandi}',numbers={$kucun} where ids='{$code}'";

if($db->query($sql)){
header("location:test.php");
}else{
echo "error";
}

  

 

转载于:https://www.cnblogs.com/sglq/p/7526811.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值