[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>
<?php
//获得需要修改的商品编号,默认修改一号商品信息
if(@$id=$_GET['id']==''){
$id=1;
}else{
$id=$_GET['id'];
}
//连接数据库
require "..\public\dbcn.php";
$dbcn->exec('set names utf8');
//取出ID对应的商品
$sql="select * from products where proID=$id";
$rs=$dbcn->query($sql);
$rows=$rs->fetch(PDO::FETCH_ASSOC);//因为只取出一条数据,所以不需要循环
//修改业务逻辑
if(isset($_POST['submit'])){
$proname=$_POST['proname'];
$proguide=$_POST['proguide'];
$proprice=$_POST['proprice'];
$proamount=$_POST['proamount'];
$proimages=$_POST['proimages'];
$proweb=$_POST['proweb'];
//拼接sql语句
$sql="update products set
proname= '$proname',
proguide='$proguide',
proprice='$proprice',
proamount='$proamount',
proimages='$proimages',
proweb='$proweb'
where proID=$id";
//执行修改语句
if($dbcn->exec($sql)){
header('location:admin.php');
}else{
echo '修改失败!';
}
}
?>
<form action="" method="post">
<table width="585" border="1" align="center">
<tr>
<td colspan="2" align="center"><strong>修改商品</strong></td>
</tr>
<tr>
<td width="120">商品名称</td> <td width="449">
<input type="text" name="proname" id="proname" value="<?php echo $rows['proname'] ?>" /></td>
</tr>
<tr>
<td>商品规格</td>
<td><input type="text" name="proguide" id="proguide" value="<?php echo $rows['proguide'] ?>" /></td>
</tr>
<tr>
<td>价格</td>
<td> <input type="text" name="proprice" id="proprice" value="<?php echo $rows['proprice'] ?>" /></td>
</tr>
<tr>
<td>库存量</td>
<td> <input type="text" name="proamount" id="proamount" value="<?php echo $rows['proamount'] ?>" /></td>
</tr>
<tr>
<td>图片地址</td>
<td><input type="text" name="proimages" id="proimages" value="<?php echo $rows['proimages'] ?>" /></td>
</tr>
<tr>
<td>网址</td><td> <input type="text" name="proweb" id="proweb" value="<?php echo $rows['proweb']?>" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="修改" />
<input type="button" name="return" id="return" value="返回"onClick="location.href='admin.php'" />
</td>
</tr>
</table>
</form>
</body>
</html>