COuld Someone help me out here. Im working on a system that the company employees can look at and edit orders that are placed in the database. Now i Have this script that i compiled from different scripts and viewing the orders isnt a problem. the problem is when i click Edit Order next to the Row i want to Edit the Form comes up but no values are in the form. How can i make the already inputted values appear in my form boxes.
<?php
include("header.php");
?>
<?php
if (!$_REQUEST['Submit']) {
orders();
} elseif ($_REQUEST['Submit'] == "Edit Order") {
editorder();
} elseif ($_REQUEST['Submit'] == "Update Order") {
updateorder();
}
function conn() {
/* set's the variables for MySQL connection */
$server = "localhost"; // this is the server address and port
$username = ""; // change this to your username
$password = ""; // change this to your password
/* Connects to the MySQL server */
$link = @mysql_connect ($server, $username, $password) or die (mysql_error());
/* Defines the Active Database for the Connection */
if (!@mysql_select_db("hilcoath_order", $link)) {
echo "<p>There has been an error. This is the error message:</p>";
echo "<p><strong>" . mysql_error() . "</strong></p>";
echo "Please Contact Your Systems Administrator with the details";
}
return $link;
}
function orders() {
$conn = conn();
$sql = "SELECT * FROM customers, orders WHERE customers.BillName=orders.BillName AND (orders.BillName = '{$_POST['BillName']}')";
$result = mysql_query($sql, $conn);
if (!$result) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
echo "<table>";
echo "<tr>";
echo "<td>PO</td> ";
echo "<td>Phone</td>";
echo "<td>Email</td>";
echo "<td>BillZip</td>";
echo "</tr>";
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo("<tr><td>" . $row["PO"] . "</td>");
echo("<td>" . $row["BillName"] . "</td>");
echo("<td>" . $row["Phone"] . "</td>");
echo("<td>" .$row["Email"] . "</td>");
echo("<td>" .$row["BillZip"] . "</td>");
echo("<td><a href=\"" . $_SERVER['PHP_SELF'] . "?PO=" . $row['PO'] . "&Submit=Edit Order\">Edit Order</a></td></tr>\n\n");
}
}
function editorder() {
$conn= conn();
$sql = "SELECT * FROM customers, orders WHERE customers.BillName=orders.BillName AND (orders.PO = '{$_REQUEST[PO]}')";
$result = mysql_query($sql, $conn);
if (!$result){
echo("<p> Error Performing Query: " . mysql_error() . "</p>");
exit();
}
?>
<form name="EditOrder" method="post" action="<?php echo $PHP_SELF?>">
<input type="text" name="PO" value="<?php echo "$row[PO]";?>"><br>
<input type="text" name="BillName" value="<?php echo "$row[BillName]";?>"><br>
<input type="text" name="Email" value="<?php echo "$row[Email]";?>"><br>
<input type="text" name="BillZip" value="<?php echo "$row[BillZip]";?>"><br>
<input type="text" name="Phone" value="<?php echo "$row[Phone]";?>"><br>
<input type="submit" name="update" value="Update Order">
</form>
<?php
}
function updateorder() {
$conn = conn();
$sql_update = "UPDATE orders SET ";
$sql_update .= "orders.BillName = '" . $_REQUEST['BillName'] . "', ";
$sql_update .= "orders.Email = '" . $_REQUEST['Email'] . "', ";
$sql_update .= "orders.BillZip = '" . $_REQUEST['BillZip'] . "', ";
$sql_update .= "orders.Phone = '" . $_REQUEST['Phone'] . "', ";
$sql_update .= "WHERE (orders.PO = " . $_REQUEST['PO'] . ")";
$result = mysql_query($sql_update, $conn);
if (!$result){
echo("<p> Error Performing Query: " . mysql_error() . "</p>");
exit();
}
}
?>