Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submission Form

Status
Not open for further replies.

rogerzebra

Technical User
May 19, 2004
216
SE
Hi again

I added to my submission form some required fields which has to be filled in otherwise it doesn't execute the form. After I added this feature something went wrong or missing, what have I done wrong or what's missing?

Code:
<?php

// connect to server, database, table.
include 'db_intranet.php';

$class_code = ($_POST['class_code']);
$date_recieved = ($_POST['date_recieved']);
$producer = ($_POST['producer']);
$name_insured = ($_POST['name_insured']);
$effective_date = ($_POST['effective_date']);
$primary_state = ($_POST['primary_state']);

/*stripslashes to make sure that's not any escaped characters */
$class_code = stripslashes($class_code);
$date_recieved = stripslashes($date_recieved);
$producer = stripslashes($producer);
$name_insured = stripslashes($name_insured);
$effective_date = stripslashes($effective_date);
$primary_state = stripslashes($primary_state);

/* required information */
if((!$date_recieved) || (!$producer) || ($name_insured)){

	echo 'You did not submit the following required information! <br />'; 
if(!$date_recieved){ 

        echo "Date recieved is a required field. Please enter it below.<br />";     
} 	
{
	 	echo 'You did not submit the following required information! <br />'; 
if(!$producer){
 
        echo "Producer is a required field. Please enter it below.<br />"; 
} 
{
	 	echo 'You did not submit the following required information! <br />'; 
if(!$name_insured){ 

        echo "Name insured is a required field. Please enter it below.<br />"; 
} 
include 'submission_form.html';
exit();
}


// insert information into the database
$query="INSERT INTO submissions (class_code, date_recieved, producer, 
			name_insured, effective_date, primary_state)
		VALUES ('$_POST[class_code]','$_POST[date_recieved]','$_POST[producer]',
			'$_POST[name_insured]','$_POST[effective_date]','$_POST[primary_state]')";

if(!mysql_db_query($database_name,$query)) die(mysql_error());
echo "success in database entry.";

echo "<br />";
echo "<a href=\"submission_form.html\">Click here to return to the form page.</a>";
?>

As usual I appreciate all help or tips that pointing me in a direction to take me forward.
Thanks in advance.
/rz
 
You have:
Code:
if((!$date_recieved) || (!$producer) || ($name_insured)){

    echo 'You did not submit the following required information! <br />'; 
if(!$date_recieved){ 

        echo "Date recieved is a required field. Please enter it below.<br />";     
}     
{
         echo 'You did not submit the following required information! <br />'; 
if(!$producer){
 
        echo "Producer is a required field. Please enter it below.<br />"; 
} 
{
         echo 'You did not submit the following required information! <br />'; 
if(!$name_insured){ 

        echo "Name insured is a required field. Please enter it below.<br />"; 
}
There are syntax errors in the above code (mis-matched "{")
I would write this as:
Code:
if(($date_recieved == '') || ($producer == '') || ($name_insured == '')){

    echo 'You did not submit the following required information! <br />'; 
if($date_recieved == '')
        echo "Date recieved is a required field. Please enter it below.<br />";          
if($producer == '')
         echo "Producer is a required field. Please enter it below.<br />";  
if($name_insured == '')
        echo "Name insured is a required field. Please enter it below.<br />";
include 'submission_form.html';
exit();
}
When you don't enter anything in a text box on a form, that variable will get a zero length string ('') so you should test for that.

Ken
 
hi kenrbnsn,

I added your code but still got the same parse error on line 61 which is the closing tag. any idea why?

thxs ken..
 
Ken,
Now it's working.. I had a curly bracket left.
thanks so much for you help Ken.
/rz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top