本想在一页面通过二个表单,POST传到本页面,完成查询和修改数据库的功能。但不成功。最终还是用了二个页面。
说明 理论实践还不扎实。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改化学仓库录入数据</title>
<style type="text/css">
#form1
{
padding:20px;
padding-left:500px;
width:100%;
height:100%;
text-align:left;
background-color:yellow;
}
#form2
{
padding:20px;
padding-left:500px;
width:100%;
height:100%;
text-align:left;
background-color:blue;
}
</style>
</head>
<body>
<a href="javascript:history.back(-1);">返回</a> <br>
<div id=form1>
<h>修改此记录数ID的数据</h><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"><br>
待修改记录ID<input type="number" name="inoutid">
<input type="submit" value="先查询">
</form>
</div>
<?php
include_once('connect.php');
$inoutid=$_POST['inoutid'];
// Check connection
if (!$conn) {
die("连接失败: " . mysqli_connect_error());
}
if(isset($_POST['inoutid'])){
$selsql="select * from table_cheminout where inoutid= $inoutid;";
$rest=mysqli_query($conn,$selsql);
if(!$rest){
die('无法查询信息'.mysqli_error($conn));
}
$row=mysqli_fetch_array($rest,MYSQLI_BOTH);
$chemnameid_ =$row['chemnameid'];
$numbers_=$row['numbers'];
$date_=$row['date'];
$remarks_=$row['remarks']; // select_end
}
mysqli_close($conn);
?>
<div id=form2>
<form action="update_chem_deal.php" method="POST"> <br>
等待修改的ID号:<input type="number" name="inoutid2" value="<?php echo $inoutid; ?>" ><br>
部    门:<select name="dept">
<option value="ZY">ZY</option>
<option value="YY">YY</option>
</select ><br>
化学品ID<input type="number" name="chemnameid" value="<?php echo $chemnameid_; ?>" ><br>
数    量:<input type="number" name="numbers" value="<?php echo $numbers_; ?>" ><br>
日    期: <input type="date" name="date" value="<?php echo $date_; ?>"><br>
备    注:<input type="text" name="remarks" value="<?php echo $remarks_ ; ?>" ><br>
<input type="reset" value="重置">
<input type="submit" value="提交" >
</form>
</div>
</body>
</html>
<?php
include_once('connect.php');
$inoutid=$_POST['inoutid2'];
$dept=$_POST['dept'];
$chemnameid = $_POST['chemnameid'];
$numbers =$_POST['numbers'];
$date=$_POST['date'];
$remarks= $_POST['remarks'];
$sqlupdate="UPDATE table_cheminout SET chemnameid=$chemnameid,numbers=$numbers,dept='$dept',date='$date',remarks='$remarks' WHERE inoutid=$inoutid;";
mysqli_query($conn ,$sqlupdate);
echo "修改成功!ok";
mysqli_close($conn);
?>
update_chem_deal.php