Forum Moderators: coopster

Message Too Old, No Replies

Problem updating rows in database

         

etrader1

1:42 am on Jun 3, 2005 (gmt 0)

10+ Year Member



I'm trying to create a form that updates the rows in
my database.

I'm not getting any error messages but the database
is not being updated. The variables work fine when
I add data using the INSERT query.

Can anyone tell me if the query and form below is
valid or why it's not updating the database.

//update database query:

$query = "UPDATE venues SET address='$address',
description='$description',
phone='$phone',
website='$website',
email='$email'
WHERE venuename='$venuename'";
$result = mysql_query($query)
or die ("Invalid input. Try again.");
echo "Venue updated successfully.<br>";

//update database form:

$query = "SELECT DISTINCT venuename FROM venues ORDER BY venuename";
$result = mysql_query($query)
or die ("Couldn’t execute query.");
echo "<form action='editvenue.php' method='POST'>";
echo "<table>\n
<tr>\n
<td>Venue name:\n
<td>\n";
echo "<select name='venuename'>\n";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<option value='venuename'>$venuename\n";
}
echo "</select></td>\n
</tr>\n
<tr>\n
<td>Description: </td>
<td><input type='text' name='description'></td>\n
</tr>\n
<tr>\n
<td>Address: </td>\n
<td><input type='text' name='address'></td>\n
</tr>\n
<tr>\n
<td>Phone: </td>\n
<td><input type='text' name='phone'></td>\n
</tr>\n
<tr>\n
<td>Email: </td>
<td><input type='text' name='email'></td>\n
</tr>\n
<tr>\n
<td>Website: </td>\n
<td><input type='text' name='website'></td>\n
</tr>\n
<tr>\n
<td colspan=\"2\" align=\"center\"><input type='submit' value='Submit'></td>\n
</tr>\n
</table>\n
</form>\n";

mgm_03

2:51 am on Jun 3, 2005 (gmt 0)

10+ Year Member



Assuming you have done a "view source" to see that your code is constructing your HTML correctly....remember that if you are updating a row with identical information, no update is performed.

in other words....mysql_affected_rows() is 0 if you are updating a row with the same data it contains.

etrader1

7:15 am on Jun 3, 2005 (gmt 0)

10+ Year Member



I found the error.

The value name in the loop was missing a $ sign:

while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<option value='$venuename'>$venuename\n";
}