OK:
Have a form that populates fields from several tables in a db if the information is there. User can edit necesary fields, and hit submit button, which updates tables.
<? php
//blah blah query db
$row = mysql_fetch_array($result);
$a2 = $row['field2'];
//display text box with existing value
echo "Room Number: <input type=\"text\" name=\"room\" value = \"".$a2."\" size=\"50\ maxlength=\"50\"><br></p>";
?>
obviously, if $num_rows($result == 0), the $room textfield is blank.
When the user hits the submit button, there can be several options:
1) if there was already data in $a2, I can simply "Update" the table with the new data in $room.
2) if there was no data in $a2, but the user added data in $room, I need to insert a new row in the table.
3) if there was data in $a2 and the user removed the data, I need to delete the row from the table.
To do this, I need to compare $a2 and $room. I know how to get the data from $room, but how do I get the data from $a2? I've tried everything I can think of, and no luck. Basic code structure (all on one page):
<? php
//connect to db
if ($POST['edit'])
{
extract($POST);
echo "room is: ".$a2; //prints "room is: " and no value for $a2
}
?>
<html>
//more html code
<body>
<form method="post">
// more html/php
<? php
//blah blah query db
$row = mysql_fetch_array($result);
$a2 = $row['field2'];
//display text box with existing value
echo "Room Number: <input type=\"text\" name=\"room\" value = \"".$a2."\" size=\"50\ maxlength=\"50\"><br></p>";
?>
<input type="submit" name="edit" value="Save Changes">
</p>
</font>
</form>
</body>
</html>
Any thoughts as to how I can get $a2 into the if statement for the edit button? Usually, I manage to miss something simple. I've tried $GET & $POST, and neither work.
Any help is appreciated!