www.webdeveloper.com
Results 1 to 6 of 6

Thread: Prefill form with data gleaned from database?

  1. #1
    Join Date
    Aug 2010
    Posts
    4

    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

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    You need to set the value of the hidden field to $row['Date_Return'] so that it is sent to schedule_update_switcher.php

  3. #3
    Join Date
    Aug 2010
    Posts
    4
    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?

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    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.

  5. #5
    Join Date
    Aug 2010
    Posts
    4
    so it should look like this, right?

    ...value="<?php echo $row['Date_Return']; ?>"...

  6. #6
    Join Date
    Aug 2010
    Posts
    4
    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
  •  
HTML5 Development Center



Recent Articles