Prefill form with data gleaned from database?
Hi,
I'm trying to prefill my form with data from a database so that the user can update their database entry. My code looks something like this.
while ($row = mysql_fetch_assoc($RESULTS)) {
echo '</td><td align=center><form name="update" action="schedule_update_switcher.php">', '<input type="submit" value="Edit" />';
echo '</td><td align=center><input type="hidden" name="Date_Return"></input></form>', $row['Date_Return'];
echo '</td></tr>';
}
The page that the user would be viewing at this point lists all entries in the database that they had previously entered. Clicking the submit button will call "schedule_update_switcher.php" (I know, long title), which prefills a form for the user to update the database entry. I want the data from $row['Date_Return'] to be prefilled into the form. Any ideas??
Grant
You need to set the value of the hidden field to $row['Date_Return'] so that it is sent to schedule_update_switcher.php
Yea I know...the problem is that I'm not sure how to do that. Everything I've tried breaks the code. Could you enlighten me?
echo $row['Date_Return'] to the value attribute of the hidden input.
I can't tell from your posts how much you know about html forms and php.
If you need help with the actual code, maybe work through the php tutorials and html forms tutorials on the w3schools website.
so it should look like this, right?
...value="<?php echo $row['Date_Return']; ?>"...
I got it. What I had to do was this:
while ($row = mysql_fetch_assoc($RESULTS)) {
echo '</td><td align=center><form name="update" action="schedule_update_switcher.php">', '<input type="submit" value="Edit" />';
echo '</td><td align=center><input type="hidden" name="Date_Return" value="', $row['Date_Return'], '"></input></form>', $row['Date_Return'];
echo '</td></tr>';
}
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks