Hey all, I've tried to find the answer to this on my own, but no such luck. I'm new to PHP.
I want to display an entire mysql table on a page as an html form, with the form field values populated with the data. that's the easy part, and I have that working.
Next, I want to have the script update the mysql table if any of the form values were changed and the "submit" button was pressed. It doesn't like my code. How should I be doing that? The code I have is as follows:
<?php
// If the form has just been submitted
if ($submit) {
// Pull the records from the table
$sql = "UPDATE $tablename SET Description=$description, Price=$price WHERE id=$id";
$result = mysql_query($sql);
} else {
// Form is being displayed for the first time
$sql = "SELECT * FROM $tablename";
$result = mysql_query($sql,$dbcnx);
}
echo "<form method=\"post\" action=\"$PHP_SELF\">\n";
echo "<table border=\"1\">\n";
echo "<tr><td>Description</td><td>Price</td></tr>\n";
if ($myrow = mysql_fetch_array($result)) {
do {
printf("<tr><td><input type=\"hidden\" name=\"id\" value=\"%s\">" .
"<input type=\"text\" name=\"description\" value=\"%s\">" .
"</td><input type=\"text\" name=\"price\" value=\"%s\">" .
"<td></tr>\n", $myrow["ID"], $myrow["Description"], $myrow["Price"]);
} while ($myrow = mysql_fetch_array($result));
} else {
echo "<tr><td>Sorry, no records were found</td></tr>\n";
}
echo "</table>\n";
echo "<input type=\"Submit\" name=\"submit\" value=\"Enter information\">\n";
echo "</form>";
?>