When the user clicks on Edit button, pass that user's id in a hidden variable, query the table, fetch the record and print respective values in the textboxes. Is there any particular error ?
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
Here is a simple example.
//this is test1.php
<html>
<body>
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("test");
$query = "select * from orders";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
echo "<form method='post' action='test2.php'>";
echo "<input type='hidden' name='orderid' value='".$row['order_id']."'>";
echo $row['order_id'];
echo "<input type='submit' name='submit' value='Edit'>";
echo "</form>";
}
?>
</body>
</html>
In this script, it lists all the order_ids from order table. You can edit an order by clicking on Edit button.
//this is test2.php
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("test");
$orderid = mysql_real_escape_string($_POST['orderid']);
$query = "select * from orders where order_id = '$orderid'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo "<form method='post' action='test3.php'>";
echo "<input type='hidden' name='orderid' value=".$row['orderid'].">";
echo "<input type='text' name='amount' value=".$row['amount'].">";
echo "<input type='submit' name=submit value=update>";
echo "</form>";
?>
order_id is passed from test1.php to this script. We get the amount of that particular order_id in this script,which is displayed in the textbox. The user can change the amount value and click on Update.
//this is test3.php
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("test");
$amount = mysql_real_escape_string($_POST['amount']);
$orderid = mysql_real_escape_string($_POST['orderid']);
$query = "update orders set amount = $amount where orderid = '$orderid'";
mysql_query($query);
header("location: test1.php");
?>
In this script, orderid and the edited amount is passed on.. Then the amount is updated in the table for that particular orderid and then redirected back to test1.php . I hope thats clear.. :)
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356