Jump to content

Recommended Posts

Ok so I am a graphic designer and I thought I could add a simple checkbox to a pre-existing form, but when I send it to the php page to process the form I get an error back can anyone help me?

 

The check box is called MonthlyPlan and it's to subscribe to a monthly newsletter...

 

Here is the php code (including the other form fields)...everything else works just fine, just the MonthlyPlan stuff for the checkbox

 

<?php
/* grabs the POST variables and puts them into variables that we can use */
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$email=$_POST['email'];
$website=$_POST['website'];
$countryCode=$_POST['countryCode'];
$phone=$_POST['phone'];
$phoneExt=$_POST['phoneExt'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$address=$_POST['address'];
$city=$_POST['city'];
$state=$_POST['state'];
$country=$_POST['country'];
$zipCode=$_POST['zipCode'];
$heardAbout=$_POST['heardAbout'];
$inquiring=$_POST['inquiring'];
$MonthlyPlan=$_POST['MonthlyPlan'];
$textarea=$_POST['textarea'];


//---------VALIDATION-------->
    if($firstName){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your first name\n";//----> ERROR if no input
            }

    if($lastName){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your last name\n";//----> ERROR if no input
            }

    if($email){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your e-mail address\n";//----> ERROR if no input
            }

    if($phone){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your phone number\n";//----> ERROR if no input
            }

    if($address){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your mailing address\n";//----> ERROR if no input
            }

    if($city){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your city name\n";//----> ERROR if no input
            }

    if($zipCode){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your zip code\n";//----> ERROR if no input
            }
//-------->ERROR FREE??
    if($error==""){
        echo "Thank you for inquiring about us! A receipt of your submission will be e-mailed to you almost immediately.";
//----------------------------------
$mailContent="--------CONTACT--------\n"
            ."First Name: ".$firstName."\n"
            ."Last Name: ".$lastName."\n"
            ."Company: ".$company."\n"
            ."E-mail: ".$email."\n"
            ."Website: ".$website."\n\n--------PHONE--------\n"
            ."Phone: ".$countryCode." ".$phone."\n"
            ."Extension: ".$phoneExt."\n"
            ."Fax: ".$fax."\n"
            ."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
            ."Street Address: ".$address."\n"
            ."City: ".$city."\n"
            ."State: ".$state."\n"
            ."Country: ".$country."\n"
            ."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
            ."Where did you hear about us? ".$heardAbout."\n"
            ."Inquiring About: ".$inquiring."\n"
		."Monthly Plan: ".$MonthlyPlan."\n"
		."Your Comments: ".$textarea."\n";
//----------------------------------
$toAddress="[email protected]";
$subject="Contact Information'";
$recipientSubject="Gravitas Contact Form";
$receiptMessage = "Thank you ".$firstName." for inquiring about Gravitas!\n\n\nHere is what you submitted to us:\n\n"
            ."--------CONTACT--------\n"
            ."First Name: ".$firstName."\n"
            ."Last Name: ".$lastName."\n"
            ."Company: ".$company."\n"
            ."E-mail: ".$email."\n"
            ."Website: ".$website."\n\n--------PHONE--------\n"
            ."Phone: ".$countryCode." ".$phone."\n"
            ."Extension: ".$phoneExt."\n"
            ."Fax: ".$fax."\n"
            ."Mobile: ".$mobile."\n\n--------ADDRESS--------\n"
            ."Street Address: ".$address."\n"
            ."City: ".$city."\n"
            ."State: ".$state."\n"
            ."Country: ".$country."\n"
            ."Zip Code: ".$zipCode."\n\n--------INFO--------\n"
            ."Where did you hear about us? ".$heardAbout."\n"
            ."Inquiring About: ".$inquiring."\n"
		."Monthly Plan: ".$MonthlyPlan."\n"
		."Your Comments: ".$textarea."\n";
//----------------------------------
mail($email, $subject, $receiptMessage,"From:$toAddress");
//----------------------------------
mail($toAddress,$recipientSubject,$mailContent,"From:$email");
//--->echo $mailContent;

////////////////////////////////////////  CONNECT TO MYSQL DB  ////////////////////
// OPEN CONNECTION --->
$connection=mysql_connect("xxx","yyy", "zzz") or die("Unable to connect!"); /* change this! */

mysql_select_db("gravitas") or die("Unable to select database!");

//  EXECUTE QUERY --->
$query="INSERT INTO generalContact (
            firstName,
            lastName,
            company,
            email,
            website,
            countryCode,
            phone,
            phoneExt,
            mobile,
            fax,
            address,
            city,
            state,
            country,
            zipCode,
            heardAbout,
            inquiringOn)
		MonthlyPlan
        VALUES(
            '".$firstName."',
            '".$lastName."',
            '".$company."',
            '".$email."',
            '".$website."',
            '".$countryCode."',
            '".$phone."',
            '".$phoneExt."',
            '".$mobile."',
            '".$fax."',
            '".$address."',
            '".$city."',
            '".$state."',
            '".$country."',
            '".$zipCode."',
            '".$heardAbout."',
		'".$MonthlyPlan."',
            '".$inquiring."')";
//////----->
$result=mysql_query($query) or die("Error in query:".mysql_error());
//if ($result)
    //echo mysql_affected_rows()." row inserted into the database effectively.";

//  CLOSE CONNECTION --->
mysql_close($connection);

///////////////////////////////////////////////////////////////////////////////////
        }
    else{

            print "Sorry, but the form cannot be sent until the fields indicated are filled out completely - \n";
            print "$error\n";
            print "\n";
            print "\n";
            print "Please use your \"Back\" button to return to the form to correct the omissions.  Thank you.\n";
        }

?>

Link to comment
https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/
Share on other sites

If I were to fill out the form with Jesse Edwards as the name the error would read:

 

"Thank you for inquiring about us! A

receipt of your submission will be e-mailed to you almost immediately. Error

in query: You have an error in your SQL syntax; check the manual that

corresponds to your Mysql server version for the right syntax to use near

'MonthlyPlan VALUES( 'Jesse', 'Edwards', ' at line 19"

Link to comment
https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225323
Share on other sites

Change your SQL insert syntax to:

 

<?php
$query="INSERT INTO generalContact (
            firstName,
            lastName,
            company,
            email,
            website,
            countryCode,
            phone,
            phoneExt,
            mobile,
            fax,
            address,
            city,
            state,
            country,
            zipCode,
            heardAbout,
            inquiringOn)
MonthlyPlan
        VALUES(
            '$firstName',
            '$lastName',
            '$company',
            '$email',
            '$website',
            '$countryCode',
            '$phone',
            '$phoneExt',
            '$mobile',
            '$fax',
            '$address',
            '$city',
            '$state',
            '$country',
            '$zipCode',
            '$heardAbout',
    '$MonthlyPlan',
            '$inquiring')"

?>

Link to comment
https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225334
Share on other sites

Your error is coming from this part of your SQL Query (mid way through):

            inquiringOn)
MonthlyPlan
        VALUES(

Notice the closing brace after the inquiringOn field but you have the MonthlyPlan field outside of the list of fields.

 

This is what's causing this error.

 

it should be like this:

            inquiringOn,
            MonthlyPlan)
        VALUES(

 

ANd the last part of the query should be like this:

            '$inquiring',
            '$MonthlyPlan')"

 

and not like this:

	    '$MonthlyPlan',
            '$inquiring')"

Your fields values where in the wrong order.

 

You must place your fields values in the correct order you list the fields in. Otherwise the data will be added to the wrong field in your database which can cause other SQL errors/problems.

 

Also looking at your code. This following code is redundant

if($firstName){//----> CHECK input
        }
        else{
            $error.="Please, go back and fill out your first name\n";//----> ERROR if no input
            }

You have an empty if statement. It is redundant code if your leave something blank/don't use it. If thats the case don't have it in there. Just do your if statement like this instead:

if(!$firstName){//----> CHECK input
    $error.="Please, go back and fill out your first name\n";//----> ERROR if no input
}

The exclamation mark (!) means NOT

Link to comment
https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225344
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.