Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/259068-cookie-not-inserting-info-into-form/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.