我有一个编辑数据表单,用户在选择框中选择要编辑的记录的ID。
然后在下一个php脚本中,我打印现有值,然后允许用户更改值。提交表单后,表单数据将使用GET发送到我的php脚本,该脚本将更新此记录的值。
我的问题是,如何将记录的id包含在表单发送的其余值中?我不想使用cookies(如果可能的话)。
这是我的代码:
第一种形式:
<?php
$myTitle = 'Interface to edit a license';
require 'header.php';
$licid = $_GET ['license_id'];
$sql = 'select * from all_license where id =' . $licid;
$result = mysqli_query ( $con, $sql );
$rowm = mysqli_fetch_array ( $result )?>
<br>
<center>
<table>
<tr>
<td class="acentre">Select below what admin task you would like to do</td>
</tr>
<tr>
<td><?php require 'admmenu.php' ?></td>
</tr>
<tr>
<td class="acentre">Displaying the current values for license id: <?php echo $licid ?></td>
</tr>
<tr>
<td><form name="license_edit" action="e2license.php" method="get">
<center>
<table>
<tr>
<th>Field Name:</th>
<th>Existing Value:</th>
<th>New Value:</th>
</tr>
<tr>
<td>License ID:</td>
<td><?php echo $licid ?></td>
<td><input type="text" value="<?php echo $licid ?>" name="licid" disabled>
<tr>
<td>Product Name:</td>
<td><?php echo $rowm['prodname'] ?></td>
<td><?php require 'cmbprodname.php';?></td>
</tr>
<tr>
<td>Supplier Name:</td>
<td><?php echo $rowm['suppliername'] ?></td>
<td><?php require 'cmbsupplier.php';?></td>
</tr>
<tr>
<td>Lease Type:</td>
<td><?php echo $rowm['leasetype'] ?></td>
<td><?php require 'cmbleasetype.php'?></td>
</tr>
<tr>
<td>Expiry Date:</td>
<td><?php echo $rowm['expirydate'] ?></td>
<td><input type="text" id="datepicker" name="expirydate"></td>
</tr>
<tr>
<td>License Price:</td>
<td><?php echo toRand($rowm['licenseprice']) ?></td>
<td><input type="text" name="price"></td>
</tr>
<tr>
<td class="aright" colspan="3"><input type="submit"></td>
</tr>
</table>
</center>
</form></td>
</tr>
</table>
</center>
<?php
require 'footer.php';
?>
然后第二个:
<?php
$licid = $_GET['licid'];
$product_id = $_GET['prodname'];
$supplier_id = $_GET['supplier'];
$leasetype_id = $_GET['leasetype'];
$expirydate = $_GET['expirydate'];
$price = $_GET['price'];
require 'conn.php';
$sql = 'update license set product_id =' . $product_id;
$sql = $sql . ', leasetype_id =' . $leasetype_id;
$sql = $sql . ', supplier_id=' . $supplier_id;
$sql = $sql . ', expirydate=' . $expirydate;
$sql = $sql . ', price=' . $price;
$sql = $sql . ' where id=' . $licid;
echo $sql;
//$result = mysqli_query ( $con, $sql );
//header("Location: http://localhost/license/admin.php");
?>
现在,$ sql的echo打印的代码是:
update license set product_id =4, leasetype_id =4, supplier_id=3, expirydate=2014-07-14, price=5000 where id=
因此,$ licid似乎没有从第一个PHP脚本转移到第二个PHP脚本(可能是因为输入被设置为禁用?。我怎样才能实现这个目标?
答案 0 :(得分:1)
我只是在表单中使用输出id的隐藏字段。
<input type="hidden" name="licid" id="licid" value="<?php echo $licid ?>">