Reputation: 1281
I have the an edit data form where the user selects the id of the record they want to edit in a selection box.
Then in the next php script I print the existing values and then allow the user to change the values. Once the form is submitted the form data is send using GET to my php script that will update the values for this record.
My problem is this, how do I include the id of the record to the rest of the values send by the form? I don't want to use cookies (if it is possible not to).
Here is my code:
The first form:
<?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';
?>
Then the second one:
<?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");
?>
Now the code printed by the echo of the $sql is:
update license set product_id =4, leasetype_id =4, supplier_id=3, expirydate=2014-07-14, price=5000 where id=
Thus, the $licid does not seem to get transferred from the first php script to the second one (possibly because the input is set to disabled?. How can I achieve this?
Upvotes: 0
Views: 53
Reputation: 541
I'd simply use a hidden field within your form which has the id outputted.
<input type="hidden" name="licid" id="licid" value="<?php echo $licid ?>">
Upvotes: 1