jesseledwards Posted April 9, 2007 Share Posted April 9, 2007 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/ Share on other sites More sharing options...
arianhojat Posted April 9, 2007 Share Posted April 9, 2007 umm... whats the error? Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225312 Share on other sites More sharing options...
jesseledwards Posted April 9, 2007 Author Share Posted April 9, 2007 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" Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225323 Share on other sites More sharing options...
Caesar Posted April 9, 2007 Share Posted April 9, 2007 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')" ?> Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225334 Share on other sites More sharing options...
obsidian Posted April 9, 2007 Share Posted April 9, 2007 You can't simply add a field to that form without adding a column to the database to store it with the way it is set up. Any time you're adding information that is being stored in a DB, you've got to build it from the ground up Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225341 Share on other sites More sharing options...
wildteen88 Posted April 9, 2007 Share Posted April 9, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225344 Share on other sites More sharing options...
jesseledwards Posted April 10, 2007 Author Share Posted April 10, 2007 Ok so changing the order fixed that problem now I get this: Error in query:Column count doesn't match value count at row 1 How do I fix that? Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225518 Share on other sites More sharing options...
AndyB Posted April 10, 2007 Share Posted April 10, 2007 Error in query:Column count doesn't match value count at row 1 How do I fix that? By having the same number of columns named as you have values in that query. Quote Link to comment https://forums.phpfreaks.com/topic/46311-solved-im-code-stupid/#findComment-225581 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.