Jump to content

Missing data in a three part form


kaustav

Recommended Posts

Hi all,

I need some guidance on some PHP questions I have. I have a three part registration form which uses sessions to pass the field values between each stage of the application form and then submits all the data to a mysql DB.  The third page of the form takes a long time to fill out as there are a lot of questions on it. By the time someone has filled out page three there data from page and two seems to have been lost as all that gets written to the DB is data entered in the third page and nothing from page one and two of the form. Why does this happen and how can I prevent this from happening so that I am guaranteed that all data is written to the DB?

 

Here's the application form:

 

http://dev.jagritiyatra.com/registration2

 

 

 

Kaustav

Link to comment
Share on other sites

Well, the link you provided does no good in diagnosing your problem since you have no debugging visible on the page, You have also not provided any code. Have you VERIFIED that the session data is being properly set and received on each page?

 

Try adding this to pages 2 and 3:

echo "<pre>";
print_r($_SESSION);
echo "</pre>";

 

Is the data from the previous pages displayed to the pages? If not, then the data is not getting set int he first place. Another possible problem is the final processing page. Is it properly accessing the session variables?

 

There's really not much anyone can do to help you without some details as to your code.

Link to comment
Share on other sites

teng82, sorry about that. Here is some code from my form and further explanation:

 

First page of form is http://dev.jagritiyatra.com/registration2/index.php

If the mandatory fields have been filled in then the next page is:

First page of form is http://dev.jagritiyatra.com/registration2/part2.php

and then the final page is on:

First page of form is http://dev.jagritiyatra.com/registration2/part3.php

When the submit button is selected the thanks.php script it run which writes all the form data to the MySQL database.

 

During testing I am filling out the form quite fast and submitted. Everything gets recorded to the database without any problem. What I am noticing is that I have some genuine records in the DB where all the fields in the DB for page 1 and 2 of the form is totally missing in the DB (even the mandatory field) but all the text entered in part3.php has been successfully saved to the DB.

 

Here is the PHP code for index.php. Following this is the code for the thank.php page which submits data to the DB.

 

<?
session_start();

$standarderror="Please ensure that all fields marked with an <em>*</em> have been filled out.";
$bError = false;
$aErrorCopy = array('','','','','','','','','','');

// valid all the form input fields and trim them. Uses the stripInvalid function in the general.php file. 	
$submitted = isset($_POST['submitted'])?trim($_POST['submitted']):'';
$title = isset($_POST['txtTitle'])?trim($_POST['txtTitle']):1;
$firstname = isset($_POST['txtFirstname'])?stripInvalid(trim($_POST['txtFirstname']),'name'):'';
$lastname = isset($_POST['txtLastname'])?stripInvalid(trim($_POST['txtLastname']),'name'):'';
$emailaddress = isset($_POST['txtEmail'])?stripInvalid(trim($_POST['txtEmail']),'emailpwd'):'';
$mobile = isset($_POST['txtMobile'])?stripInvalid(trim($_POST['txtMobile']),'name'):'';
$landline = isset($_POST['txtLandline'])?stripInvalid(trim($_POST['txtLandline']),'name'):'';
$address = isset($_POST['txtAddress'])?stripInvalid(trim($_POST['txtAddress']),'name'):'';
$postcode = isset($_POST['txtZIP'])?stripInvalid(trim($_POST['txtZIP']),'name'):'';
$country = isset($_POST['txtCountry'])?trim($_POST['txtCountry']):1;
$age = isset($_POST['intAge'])?trim($_POST['intAge']):1;
$gender = isset($_POST['txtGender'])?trim($_POST['txtGender']):1;

if ($submitted) {

	// firstname
	if (strlen($firstname)<1) {
		$bError = true;
		$aErrorCopy[1] = "Please enter a valid first name. It must be more than one character long. Don't use initials, instead enter your full first name.";
	}
	if (empty($firstname)) {
		$bError = true;
		$aErrorCopy[1] = "You must tell us your first name.";
	}

	// lastname
	if (strlen($lastname)<1) {
		$bError = true;
		$aErrorCopy[2] = "Please enter a valid last name which contains more than one character. Don't use initials, instead enter your full last name.";
	}
	if (empty($lastname)) {
		$bError = true;
		$aErrorCopy[2] = "You must tell us your last name.";
	}

	// email address
	if (empty($emailaddress) || (!isValidEmail($emailaddress))) {
		$bError = true;
		$aErrorCopy[3] = "Please enter a valid email address.";
	}

	// address
	if (empty($address)) {
		$bError = true;
		$aErrorCopy[4] = "Please tell us your address.";
	}

	// postcode
	if (strlen($postcode)<1) {
		$bError = true;
		$aErrorCopy[5] = "Please tell us your PIN/ZIP/postcode.";
	}
	// country
	if (strlen($country)<1) {
		$bError = true;
		$aErrorCopy[6] = "Please tell us which country you live in.";
	}
	// age
	if (strlen($age)<1) {
		$bError = true;
		$aErrorCopy[7] = "Please tell us your age.";
	}
	// gender
	if (strlen($gender)<1) {
		$bError = true;
		$aErrorCopy[8] = "Please tell your gender/sex.";
	}

if (!$bError) {
	// page validates so save data and move on	
	$_SESSION['title'] = $title;
	$_SESSION['firstname'] = $firstname;
	$_SESSION['lastname'] = $lastname;
	$_SESSION['emailaddress'] = $emailaddress;
	$_SESSION['mobile'] = $mobile;
	$_SESSION['landline'] = $landline;
	$_SESSION['address'] = $address;
	$_SESSION['postcode'] = $postcode;
	$_SESSION['country'] = $country;
	$_SESSION['age'] = $age;
	$_SESSION['gender'] = $gender;
	redirect ("part2.php");
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Registration page - Jagriti Yatra - Awakening Entrepreneurship</title>
<?php include (SITE_BASE . '/includes/header.php'); ?>
<?php include (SITE_BASE . '/includes/coreleftnav.php'); ?>
</ul>
</div>
<div id="mainContent">
	<h1>Register to join Jagriti Yatra</h1>
		<div style="padding: 5px 5px 5px 5px;background-color:#ff9999;font-weight:bold;color:#000000;border-color:#000000;border-style:dashed;margin-bottom:5px;">
		You can now register online using the form on this page, or you can <a href="/downloads/regforms/english.dot">download a Microsoft Word Temlate</a> and fill it out on a computer then either cut and paste the details in to the online form or <a href="mailto:registrations@jagritiyatra.com">email it to us</a>. Alternatively, you may print out the form on paper, fill it in by hand, and post it to us at our office in India. The Address is stated in the Word Template. We will soon be publishing registration forms in other Indian languages so watch this space. 
		</div>
<p>Full registration for Jagriti Yatra is now open. You could be one of the 450 people selected to join the yatra which kicks off on 1st May 2008. We are seeking participants between the age of 18-25 to apply, especially those who have an interest in learning how to scale up grass roots social and business initiatives. If your application is succesful, you will have the opportunity to meet and learn from the real heroes and change makers of India and pick up on invaluable, life changing experience.</p>
<p>Once you submit this form, your application will go through an extensive selection process. Further details of the selection process will be published on this web site at a later date. To stand a good chance to be selected, we encourage you to think carefully about your answers to the questions asked on the application form below.</p>
<p><h2>Registration - Part 1 of 3</h2></p>
<?php
if ($bError) echo "<p>".$standarderror."</p>";
?>

<form action="index.php" method="post" name="register" id="register">
<label>Title</label>
		<select name="txtTitle">
			<option value="Mr" <? if ($country=='Mr') { echo 'selected=\"selected\"';}?>>Mr</option>
			<option value="Mrs" <? if ($country=='Mrs') { echo 'selected=\"selected\"';}?>>Mrs</option>
			<option value="Ms" <? if ($country=='Ms') { echo 'selected=\"selected\"';}?>>Ms</option>
			<option value="Dr." <? if ($country=='Dr.') { echo 'selected=\"selected\"';}?>>Dr.</option>
			<option value="Prof." <? if ($country=='Prof.') { echo 'selected=\"selected\"';}?>>Prof.</option>
		</select>			
<label>First Name <em>*</em></label>
		<input name="txtFirstname" type="text" value="<?=$firstname?>" size="40" />
		<span class="error"><?=$aErrorCopy[1];?></span>
<label>Last Name <em>*</em></label>
		<input name="txtLastname" type="text" value="<?=$lastname?>" size="40" />
		<span class="error"><?=$aErrorCopy[2];?></span>
<label>Email <em>*</em></label>
		<input name="txtEmail" type="text" value="<?=$emailaddress?>" size="40 "/>
		<span class="error"><?=$aErrorCopy[3];?></span>
<label>Mobile number <small>(inc. international country code)</small></label>
		<input name="txtMobile" type="text" value="<?=$mobile?>" size="40" />
<label>Land line phone number <small>(inc. international country code)</small></label>
		<input name="txtLandline" type="text" value="<?=$landline?>" size="40" />
<label>Address <em>*</em></label>
		<textarea name="txtAddress" cols="39" rows="6"><?=$address?></textarea>
		<span class="error"><?=$aErrorCopy[4];?></span>
<label>Post code (ZIP code/PIN) <em>*</em></label>
		<input name="txtZIP" type="text" value="<?=$postcode?>" size="10" />
		<span class="error"><?=$aErrorCopy[5];?></span>
<label>Country of residence <em>*</em></label>
		<select name="txtCountry"><option value="">Please select</option>
			<option value="IN" <? if ($country=='IN') { echo 'selected=\"selected\"';}?>> India</option> 
			<option value="GB" <? if ($country=='GB') { echo 'selected=\"selected\"';}?>> United Kingdom </option>  
			<option value="US" <? if ($country=='US') { echo 'selected=\"selected\"';}?>> United States </option>
			</select>
		<span class="error"><?=$aErrorCopy[6];?></span>
		<label>Age <em>*</em></label>
		<select name="intAge" value="<?=$age?>">
			<option value="">Please select</option>
			<option value="18" <? if ($age=='18') { echo 'selected=\"selected\"';}?>>18</option>
			<option value="19" <? if ($age=='19') { echo 'selected=\"selected\"';}?>>19</option>
			<option value="20" <? if ($age=='20') { echo 'selected=\"selected\"';}?>>20</option>
		</select>
	<span class="error"><?=$aErrorCopy[7];?></span>
	<label>Gender <em>*</em></label>
			<select name="txtGender" value="<?=$gender?>">
				<option value="">Please select</option>
				<option value="M" <? if ($gender=='M') { echo 'selected=\"selected\"';}?>>Male</option>
				<option value="F" <? if ($gender=='F') { echo 'selected=\"selected\"';}?>>Female</option>
			</select>
			<span class="error"><?=$aErrorCopy[8];?></span>
			<input type="hidden" name="submitted" value="true" />
			<div class="topspacer"><strong>[1]</strong>   [2]   [3]<input type="submit" name="submit" class="registrationbutton" value="next page"/></div>
	</form>
</div>
</div>  


 

Here's the code for the thanks.php page:

 

<?
session_start();

define(SITE_BASE, dirname(__FILE__) . '/..');	

require ('general.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Registration confirmation page - Jagriti Yatra - Awakening Entrepreneurship</title>
<?php include (SITE_BASE . '/includes/header.php'); ?>
<?php include (SITE_BASE . '/includes/coreleftnav.php'); ?>
</ul>
</div>
<div id="mainContent"><h1>Thank you for registering</h1>

<?
if(!isset($_SESSION['submitted'])) {
echo "<em>You didn't fill out the whole form. Please go back to the <a href=\"index.php\">beginning of the form</a>.</em>";
}

if(isset($_SESSION['submitted']))
{
$Title = $_SESSION['title'];
$Firstname = $_SESSION['firstname'];
$Lastname  = $_SESSION['lastname'];
$Email = $_SESSION['emailaddress'];
$Mobile = $_SESSION['mobile'];
$LandLine = $_SESSION['landline'];
$Address = $_SESSION['address'];
$ZIP = $_SESSION['postcode'];
$Country = $_SESSION['country'];
$Age = $_SESSION['age'];
$Gender = $_SESSION['gender'];
$Selffunded = $_SESSION['selffunded'];
$Education = $_SESSION['educationlevel'];
$Vocation = $_SESSION['vocation'];
$BeSocialorBusinessEntr = $_SESSION['besocialorbusinessentr'];
$WouldLikeToBe = $_SESSION['wouldliketobe'];
$FacilitatorQuestion = $_SESSION['facilitatorquestion'];
$RoleModel = $_SESSION['rolemodel'];
$AlreadyDoneSomething = $_SESSION['alreadydonesomething'];
$IndiasBiggestChallenge = $_SESSION['indiasbiggestchallenge'];
$YourContribution = $_SESSION['yourcontribution'];
$WhyYouSelected = $_SESSION['whyyouselected'];
$Yatra = ($_SESSION['optinyatra']== "on") ? 1 : 0;
$Other = ($_SESSION['optinother']== "on") ? 1 : 0;

$dbhost = 'xxx.xxx.xxx';
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$dbname = 'xxxxx';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

mysql_select_db($dbname);

    $query = "INSERT INTO xxxxxx (Datesubmitted,title,firstName, lastName, email, mobile, landline, address, zip, country, age, gender, selffunded, education, vocation, BeSocialorBusinessEntr, WouldLikeToBe, FacilitatorQuestion, RoleModel, AlreadyDoneSomething, IndiasBiggestChallenge, YourContribution, WhyYouSelected, optinYatra, optinOther) values (current_date,'$Title','$Firstname', '$Lastname', '$Email', '$Mobile', '$LandLine', '$Address', '$ZIP', '$Country', '$Age', '$Gender', '$Selffunded', '$Education', '$Vocation', '$BeSocialorBusinessEntr', '$WouldLikeToBe', '$FacilitatorQuestion', '$RoleModel', '$AlreadyDoneSomething', '$IndiasBiggestChallenge', '$YourContribution', '$WhyYouSelected', $Yatra, $Other)";

mysql_query($query) or die ('Error, insert query failed');

/*$query = "FLUSH PRIVILEGES";
mysql_query($query) or die ('Error, insert query failed');
*/

mysql_close($conn);	

echo "Thank you for completing the Jagriti Yatra registration form.";

session_destroy();
?>

Link to comment
Share on other sites

Hi mjdamato,

Thanks for your suggestions. Before I put the form live a few days ago I did exactly what you suggested and echo'ed out all the session variables to screen and I can confirm that all the field data was displayed correctly on the final thank you page. I hope the code snippets shown above prove useful to your analysis of the problem.

 

Kaustav

Link to comment
Share on other sites

I think that was for me.

 

I'm not sure about how long session data is stored, but here is a simple solution to your problem.

 

On the 2nd page of the form, take the POST data from page 1 and populate hidden fields. So, when page 2 is submitted page 3 received all of page 1 and page 2 data in the POST. Likewise, on page 3 take that POST data and populate hidden fields. Then when page 3 is submitted to the final processing page ALL the data from the three pages are submitted in the POST. This will prevent any problems you may be having by using SESSION.

Link to comment
Share on other sites

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.