这是我的edit_purchase.php代码
<?php
include "header.php";
$connect= mysqli_connect("localhost", "root","","sales");
$id=$_GET["id"];
$result=mysqli_query($connect,"SELECT p. *,e. *,h.*,s. * FROM elimo_purchase AS p
JOIN elimo_type AS e
ON p.e_type = e.tid
JOIN hw_version AS h
ON p.hw_type = h.hid
JOIN sw_version AS s
ON p.sw_type = s.sid
WHERE id='$id' ORDER BY id DESC");
while($row= mysqli_fetch_array($result)){
$serial_no=$row["serial_no"];
$date=$row["date"];
$e_type=$row["e_type"];
$hw_type=$row["hw_type"];
$sw_type=$row["sw_type"];
$type=$row["type"];
$htype=$row["htype"];
$stype=$row["stype"];
$key=$row["key"];
$hid=$row["hid"];
$sid=$row["sid"];
}
function show_e_type($connect)
{
$output1 = '';
$query1= "SELECT * FROM elimo_type";
$res1 = mysqli_query($connect, $query1);
while($row1 = mysqli_fetch_array($res1))
{
$output1 .= '<option value="'.$row1["tid"].'">'.$row1["type"].'</option>';
}
return $output1;
}
function show_hw_type($connect)
{
$output2= '';
$query2 = "SELECT * FROM hw_version";
$res2 = mysqli_query($connect, $query2);
while($row2 = mysqli_fetch_array($res2))
{
$output2 .= '<option value="'.$row2["hid"].'">'.$row2["htype"].'</option>';
}
return $output2;
}
function show_sw_type($connect)
{
$output3 = '';
$query3 = "SELECT * FROM sw_version";
$res3 = mysqli_query($connect, $query3);
while($row3 = mysqli_fetch_array($res3))
{
$output3 .= '<option value="'.$row3["sid"].'">'.$row3["stype"].'</option>';
}
return $output3;
}
?>
<div class="container">
<div class="row">
<div class="col-lg-offset-3 col-lg-6">
<div class="panel" style="border: 1px solid teal;">
<div class="panel-heading" style="background-color: teal; color: white;">
<h4>Edit: <?php echo $serial_no; ?></h4>
</div>
<div class="panel-body">
<form class="form-group" name="form1" action="" method="post" enctype="multipart/form-data">
<table width="100%">
<tr>
<td>Serial No</td>
<td>
<input type="text" name="serial_no" value="<?php echo $serial_no; ?>" class="form-control"><br>
</td>
</tr>
<tr>
<td>Type</td>
<td>
<select name="e_type" class="form-control">
<?php echo show_e_type($connect); ?>
</select><br>
</td>
</tr>
<tr>
<td>Hardware Version</td>
<td>
<select name="hw_type" class="form-control">
<?php echo show_hw_type($connect); ?>
</select><br>
</td>
</tr>
<tr>
<td>Software Version</td>
<td>
<select name="sw_type" class="form-control">
<?php echo show_sw_type($connect); ?>
</select><br>
</td>
</tr>
<tr>
<td>Key</td>
<td>
<input type="text" name="key" value="<?php echo $key; ?>" class="form-control"><br>
</td>
</tr>
<tr>
<td>Date</td>
<td>
<br><input type="text" name="date" value="<?php echo $date; ?>" class="form-control"><br>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<br><input type="submit" name="submit1" value="Update" class="btn btn-teal">
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
</div>
<?php
if(isset($_POST["submit1"])){
mysqli_query($connect,"UPDATE `elimo_purchase` SET serial_no='$_POST[serial_no]',e_type='$_POST[e_type]',hw_type='$_POST[hw_type]',sw_type='$_POST[sw_type]',key='$_POST[key],'date='$_POST[date]' where id=$id");
echo '
<script type="text/javascript">
window.location="index.php";
</script> ';
}
?>
提交时不会更新数据。从其他数据库表中提取e_type,hw_type和sw_type。 当我在编辑表单中更改数据时,数据表中的数据不会更改。它保持不变。任何人都可以找到错误的代码,因为我被困在那里的代码。
答案 0 :(得分:-1)
您修复时出现语法错误
mysqli_query($connect,"UPDATE `elimo_purchase` SET serial_no='".$_POST['serial_no']."',e_type='".$_POST['e_type']."',hw_type='".$_POST['hw_type']."',sw_type='".$_POST['sw_type']."',key='".$_POST['key']."',date='".$_POST['date']."' where id='$id'");
希望这对你有用。