Hi, I've set up a form to capture data in order to form a profile about a user. The form consists of some text boxes, drop down menus + combo boxes. The code for the form is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>iFile profile edit</title> </head> <body> <?php $sql = "SELECT * FROM `ifile` WHERE `if_PU_UPN` = 'P392206099011'"; include("../includes/php/connect.php"); while ($row = mysql_fetch_assoc($rst)) { $first_name = $row['if_Forename']; $surname = $row['if_Surname']; $select_day = $row['if_DOBDD']; $select_month = $row['if_DOBMM']; $select_year = $row['if_DOBYYYY']; $subject = $row['if_Sub']; $film = $row['if_Field1']; $special = $row['if_Field2']; $moment = $row['if_Field3']; $hobbies = $row['if_Field4']; $computer = $row['if_Comp']; $siblings = $row['if_Sibling']; $visit = $row['if_School']; $question1 = $row['if_Question1']; $question2 = $row['if_Question2']; $question3 = $row['if_Question3']; } ?> <form action = "<?php echo $PHP_SELF; ?>" method = "post" > <table width = "800" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <th width = "22%" height="28" align = "left" valign = "top"> <font face = "arial" size = 2>First name:</font> </th> <td align = "left"> <input type = "text" name = "firstname" size = "30" maxlength = "30" value = "<?php echo $first_name; ?>" /> </td> </tr> <tr> <th align = "left" valign="top"> <font face = "arial" size = 2>Surname:</font> </th> <td align = "left"> <input type = "text" name = "surname" size = "30" maxlength = "30" value = "<?php echo $surname; ?>" /> </td> </tr> </table> <table width = "800" height="31" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <th align = "left" valign = "top" width = "176"> <font face = "arial" size = 2>My Birthday is....</font> </th> <td align = "left" width = "59"> <select name = "select_day" value = "<?php echo $select_day; ?>" /> <option value = "DD">DD</option> <option value = "1">1</option> <option value = "2">2</option> <option value = "3">3</option> <option value = "4">4</option> <option value = "5">5</option> <option value = "6">6</option> <option value = "7">7</option> <option value = "8">8</option> <option value = "9">9</option> <option value = "10">10</option> <option value = "11">11</option> <option value = "12">12</option> <option value = "13">13</option> <option value = "14">14</option> <option value = "15">15</option> <option value = "16">16</option> <option value = "17">17</option> <option value = "18">18</option> <option value = "19">19</option> <option value = "20">20</option> <option value = "21">21</option> <option value = "22">22</option> <option value = "23">23</option> <option value = "24">24</option> <option value = "25">25</option> <option value = "26">26</option> <option value = "27">27</option> <option value = "28">28</option> <option value = "29">29</option> <option value = "30">30</option> <option value = "31">31</option> </select> </td> <td align = "left" width = "60"> <select name = "select_month" value = "<?php echo $select_month; ?>" /> <option value = "MM">MM</option> <option value = "01">01</option> <option value = "02">02</option> <option value = "03">03</option> <option value = "04">04</option> <option value = "05">05</option> <option value = "06">06</option> <option value = "07">07</option> <option value = "08">08</option> <option value = "09">09</option> <option value = "10">10</option> <option value = "11">11</option> <option value = "12">12</option> </select> </td> <td align = "left" width = "505"> <select name = "select_year" value = "<?php echo $select_year; ?>" /> <option value = "YYYY">YYYY</option> <option value = "1994">1994</option> <option value = "1995">1995</option> <option value = "1996">1996</option> <option value = "1997">1997</option> <option value = "1998">1998</option> <option value = "1999">1999</option> <option value = "2000">2000</option> </select> </td> </tr> </table> <table width = "800" height="53" border = "0" cellpadding = "0" cellspacing = "0"> <tr> <th width="176" align = "left" valign="top"> <font face = "arial" size = 2>My favourite film is....</font> </th> <td width="624" align = "left"> <input type = "text" name = "film" size = "57" maxlength = "50" value = "<?php echo $film; ?>" /> </td> </tr> <tr> <th align = "left" valign="top"> <font face = "arial" size = 2>My favourite subject is....</font> </th> <td align = "left"> <input type = "text" name = "subject" size = "57" maxlength = "50" value = "<?php echo $subject; ?>" /> </td> </tr> </table> <table width="800"> <tr> <th align = "left"> <font face = "arial" size = 2><strong>What makes me special....all about me</strong></font> </th> </tr> <td> <textarea name = "special" cols = "65" rows = "7" /><?php echo $special; ?></textarea></td> </tr> </table> <table width="800"> <tr> <th align = "left"> <font face = "arial" size = 2><strong>Most memorable moment....</strong></font> </th> </tr> <td> <textarea name = "moment" cols = "65" rows = "2" /><?php echo $moment; ?></textarea></td> </tr> </table> <table width="800"> <tr> <th align = "left"> <font face = "arial" size = 2><strong>What I do outside of lessons/school....</strong></font> </th> </tr> <td> <textarea name = "hobbies" cols = "65" rows = "5" /><?php echo $hobbies; ?></textarea></td> </tr> </table> <table width = "547" border = "0" cellpadding = "2" cellspacing = "2"> <tr> <td align = "left" width = "179" style = "border:1px solid #000000;"><font face = "arial" size = 2>Do you have a computer at home with Internet access?</font></td> <td align = "left" width = "178" style = "border:1px solid #000000;"><font face = "arial" size = 2>Have you a brother or sister at the school?</font></td> <td align = "left" width = "170" style = "border:1px solid #000000;"><font face = "arial" size = 2>Have you been to the school before?</font></d> </tr> <tr> <td align = "center" style = "border:1px solid #000000;"> <input type = "radio" name = "computer" value = "yes" /> Yes <input type = "radio" name = "computer" value = "no" checked /> No </td> <td align = "center" style = "border:1px solid #000000;;"> <input type = "radio" name = "siblings" value = "yes" /> Yes <input type = "radio" name = "siblings" value = "no" checked /> No </td> <td align = "center" style = "border:1px solid #000000;"> <input type = "radio" name = "visit" value = "yes" /> Yes <input type = "radio" name = "visit" value = "no" checked /> No </td> </tr> </table> <table width="800"> <tr> <th align = "left"> <font face = "arial" size = 2><strong>Question 1 I would like answering about coming to High School....</strong></font> </th> </tr> <td> <textarea name = "question1" cols = "65" rows = "2" /><?php echo $question1; ?></textarea></td> </tr> </table> <table width="800"> <tr> <th align = "left"> <font face = "arial" size = 2><strong>Question 2 I would like answering about coming to High School....</strong></font> </th> </tr> <td> <textarea name = "question2" cols = "65" rows = "2" /><?php echo $question2; ?></textarea></td> </tr> </table> <table width="800"> <tr> <th align = "left"> <font face = "arial" size = 2><strong>Question 3 I would like answering about coming to High School....</strong></font> </th> </tr> <td> <textarea name = "question3" cols = "65" rows = "2" /><?php echo $question3; ?></textarea></td> </tr> <tr> <td align = "left"> <input type = "submit" name = "submit_form" value = "Save changes" /> </td> </tr> </table> </form> <?php if ($_POST['submit_form']) { $first_name = $_POST['firstname']; $surname = $_POST['surname']; $select_day = $_POST['select_day']; $select_month = $_POST['select_month']; $select_year = $_POST['select_year']; $subject = $_POST['subject']; $film = $_POST['film']; $special = $_POST['special']; $moment = $_POST['momemt']; $hobbies = $_POST['hobbies']; $computer = $_POST['computer']; $siblings = $_POST['siblings']; $visit = $_POST['visit']; $question1 = $_POST['question1']; $question2 = $_POST['question2']; $question3 = $_POST['question3']; $sql3 = "UPDATE ifile SET `if_Surname` = '$surname', `if_Forename` = '$first_name', `if_DOBDD` = '$select_day', `if_DOBMM` = '$select_month', `if_DOBYYYY` = '$select_year', `if_Sub` = '$subject', `if_Field1` = '$film', `if_Field2` = '$special', `if_Field3` = '$moment', `if_Field4` = '$hobbies', `if_Comp` = '$computer', `if_Sibling` = '$siblings', `if_School` = '$visit', `if_Question1` = '$question1', `if_Question2` = '$question2', `if_Question3` = '$question3' WHERE `if_PU_UPN` = 'P392206099011'"; include("../includes/php/connect3.php"); } ?> </body> </html> HTML: When the form is posted the values entered into each of the inputs are inserted into the database. However the screen refreshes + displays the previous values. Ideally, what I want to happen is for the values the user has typed to remain on the screen when the user clicks the "Save changes" button. Any ideas? Regards.
I don't see the INSERT statement. The code you've given only takes the info from the database and shows it on screen. No matter if you've just opened the page or submitted the form - the result is all the same. Either you haven't given the whole code or the code just haven't been written to do the stuff you describe.
Sorry, at the bottom of the script there is an UPDATE statement. I used an UPDATE statement because each user already has a record in the database so no record needs inserting. The existing data needs updating rather than new data being inserted.
OK then. The problem is exactly the update statement being at the bottom of the page. What happens is this - you change some stuff in the form and post it. When the page loads again the OLD data is extracted from the database and the update is done after that - at the end of the script. So, when you refresh again you'll see the new data, but the first time it's the old one. Move you UPDATE statement above the SELECT and all shall be fine
That works really well! Thank you very much! However, the only problem I have now is geting the drop down menus + radio buttons to display the values from the database rather than resetting to their default values. Any ideas?
Yes, i thought you might wanna do this but i forgot to tell you how. Take the fallowing code: <option value = "1994">1994</option> <option value = "1995">1995</option> <option value = "1996">1996</option> <option value = "1997">1997</option> <option value = "1998">1998</option> <option value = "1999">1999</option> <option value = "2000">2000</option> </select> PHP: And change it to for($i = 1994; $i < 2001; $i++) { printf("<option value = '%s' %s>%s</option>", $i, ($select_year == $i) ? 'selected' : '', $i); } PHP: Do the same thing with the other select boxes as well. Hope you got the idea