Hey guys,
Quick one for ya. I'm trying to write some code that pulls a column of data from a MySQL database into form fields. The form fields can be changed, and then upon submit, the form will post to itself and run an update query to modify the database.
I've successfully pulled the records from that column into a form, but upon submit it does not change the records. Please take a look at my code if you have a moment, as I'm sure that I'm missing just one or two things in the Update query. Thanks!
The update query on top of the page:
<?php
if (isset($_POST['database'])) {
db_connect();
$query = "UPDATE rates SET program=" . $_POST['value'] "where program=$row[0]";
$result = @mysql_query ($query);
?>
The Form in the body of the page:
<form name="updaterecord" id="updaterecord" method="post" action="">
<?php
db_connect();
$query = "SELECT program FROM rates";
$result = @mysql_query($query);
$num = mysql_num_rows($result);
$i = 0;
if ($num > 1) {
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$newid = "program" . $i;
echo "<input name='$newid' id='$newid' value='$row[0]' /><br />";
$i++;
}
mysql_free_result ($result);
}
else { ?>
<p>Sorry, no rates could be found. Please try again later. </p>
<p> <? mysql_error(); ?> </p> <?
}
mysql_close();?>
<input type="submit" name="database" id="database" value="Update" />
</form>