learningcurve Posted March 16, 2012 Share Posted March 16, 2012 I have a form that was written by another person. It submits registration information into a mysql db. It also sets a cookie so that if the person wants to register someone else it will prefill certain boxes of the form. The form is working and submitting data, sending them to a thank you page and the cookie is storing the correct data, but the form is not getting the prefilled data. Here is the cookie that is working (I have substituted the name of the database, path and domain for security reasons): $newID = submitForm($_POST,'conference table',"registration$thisyear"); $_POST['id'] = $newID; setcookie('last_id',$newID,0, 'path','domain'); Here is the part on the thank you page that doesn't seem to work and populate the form: if (isset($_COOKIE['last_id'])) { mysql_connect('mysql','username','password'); $based = mysql_real_escape_string($_COOKIE['last_id']); $result = mysql_query("SELECT `localornot`,`institution`,`city`,`state`,`zip`,`chooseCountry`,`country` FROM `conferencetable`.`registration$thisyear` WHERE `id`='$based' LIMIT 1;"); $row = mysql_fetch_assoc($result); if ($row['localornot']=='Yes') echo "<p>If you would like to register an additional person from our institution, click the button below and you will be taken back to the form, which will our information pre-filled for you.</p>"; else echo "<p>If you would like to register an additional person from the same institution, click the button below and you will be taken back to the form, which will have your institution's information pre-filled for you.</p>"; echo '<form id="theForm" action="index.php" method="POST"><p>'; foreach ($row as $key=>$value) echo "<input type='hidden' name='$key' value='$value'>"; echo '<input type="submit" name="another" value="Register another person"></p></form>'; } Any guidance would be appreciated. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted March 16, 2012 Share Posted March 16, 2012 Your first bit of code is using $_POST backward and calls function submitForm, which we cannot see. Your second bit seems ok, but it pulls from a database table which, again, we cannot see (and is named/designed wrong). That table is never inserted into. Quote Link to comment Share on other sites More sharing options...
learningcurve Posted March 16, 2012 Author Share Posted March 16, 2012 Okay, Thanks ManiacDan The data gets posted to the table just fine and the cookie does store the id number. Regarding the second bit, I guess I was unclear. Based on the cookie using the stored id number, the data listed gets pulled from the registration table and prepopulated into the correct spaces on the form. At least that is what is supposed to happen. I have tested and I know the data gets originally placed into the mysql registration table and the id number is stored, but after that is where it fails. There are several pages that handle all the functions for this registration piece. I am fairly new to php and this is more complicated than I have managed before. I will go back and do some more looking at the page that processes the form and see if there is something I can see there. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted March 16, 2012 Share Posted March 16, 2012 foreach ($row as $key=>$value) echo "<input type='hidden' name='$key' value='$value'>"; That code produces a HIDDEN input for every piece of data in the table. Perhaps you don't want hidden? Quote Link to comment Share on other sites More sharing options...
learningcurve Posted March 16, 2012 Author Share Posted March 16, 2012 Okay, that is a good clue... this gives me something to research. I don't know why the code currently has the input hidden, so I will start investigating there. Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.