I can't seem to grasp what is causing this error. I am new to php and doing this survey for a school project. Any help would be appreciated. <html> <head> <title>Food Survey Results</title> </head> <body> <h1>Your Food Survey</h1> <h2>Poll Results</h2> <?php var frmvalidator = new Validator("register"); frmvalidator.EnableOnPageErrorDisplay(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email address"); frmvalidator.addValidation("email","email","Please provide a valid email address"); frmvalidator.addValidation("username","req","Please provide a username"); frmvalidator.addValidation("password","req","Please provide a password"); function RegisterUser() { if(!isset($_POST['submitted'])) { return false; } $formvars = array(); if(!$this->ValidateRegistrationSubmission()) { return false; } $this->CollectRegistrationSubmission($formvars); if(!$this->SaveToDatabase($formvars)) { return false; } if(!$this->SendUserConfirmationEmail($formvars)) { return false; } $this->SendAdminIntimationEmail($formvars); return true; } if(isset($_POST['submit'])){ } $foodquestion = $_POST['foodquestion']; if(!empty($_POST['foodanswer'])){ $foodanswer = $_POST['foodanswer']; echo"<p>You have chosen:<b>".$foodanswer."</b> as your favorite food!</p>"; } else { $foodanswer = FALSE; echo"<p><font color='red'>Please tell us your favorite food!</font></p>"; } $vegiequestion = $_POST['vegiequestion']; if(!isset($_POST['vegieanswer'])){ $vegieanswer = FALSE; echo "<p><font color='red'><b>Please answer the question!</b></font> </p>"; } else { $vegieanswer = $_POST['vegieanswer']; echo"<p><font color='navy'>You checked:<b>"; foreach($vegieanswer as $v){ echo $v."|"; } } echo"</b></font></p>"; $icecreamquestion = $_POST['icecreamquestion']; if(!isset($_POST['icecreamanswer'])){ $icecreamanswer = FALSE; echo"<p><font color='red'><b>Please answer the question!</b></font></p>"; }else{ $icecreamanswer = $_POST['icecreamanswer']; switch($icecreamanswer){ case 'Yes': echo"<p><font color='navy'>You said that you<b><font color='green'> do </font></b>like mint chocolate chip ice cream!</font></p>"; break; case'No': echo"<p><font color='navy'>You said taht you <b>DO NOT</b> like mint chocolate chip ice cream!</font></p>"; break; } } $careerquestion = $_POST['careerquestion']; $careeranswer = $_POST['careeranswer']; if($careeranswer == 'none'){ $careeranswer = FALSE; echo "<p><font color='red'><b>Please answer the question!</b></font></p>"; } else { $careeranswer = $_POST['careeranswer']; echo"<p><font color='navy'>You answered that kids mostly aspire to be a(n) ".$careeranswer."!</font></p>"; } $experiencequestion = $_POST['experiencequestion']; if(!empty($_POST['experienceanswer'])){ $experienceanswer = $_POST['experienceanswer']; echo"<p><font color='navy'>Your favorite experience is " .$experienceanswer."!</font> </p>"; } else { $experienceanswer = FALSE; echo"<p><font color='red'><b>There was an error, please try your response again!</b></font></p>"; } if ($foodanswer != FALSE && $vegieanswer != FALSE && $icecreamanswer != FALSE && $careeranswer != FALSE && $experienceanswer != FALSE) { $newV = implode(' | ',$vegieanswer); $body = "<html><head></head><body>Hi Joe Randolph!<br />Your poll has just been completed. Here are the results:<br /><br /> 1. " . $foodquestion . "<br /> Answer: " . $foodanswer . "<br /><br /> 2. " . $vegiequestion . "<br />Answer: " . $newV . "<br /><br /> 3. " . $icecreamquestion . "<br />Answer: " . $icecreamanswer . "<br /><br /> 4. " . $careerquestion . " <br />Answer: " . $careeranswer . "<br /><br /> 5. " . $experiencequestion . "<br /> Answer: " . $experienceanswer . "<br /></body></html>"; $headers = "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1\n" . "From: Your Survey webby@creativewebsolutions.net"; $to = 'webby@creativewebsolutions.net'; $subject = 'Poll Results'; mail ($to, $subject, $body, $headers); echo "<h2>Your information has been sent to the owner of the survey. Thank you for participating!"; } else { echo "<p><font color='red'><b>Your information could not be sent because of one or more errors. Please try again.</b></font></p>"; } ?> </body> </html> PHP:
This is the second post I have put on this site. I am just learning. If there is something wrong and a better way to do things, suggestions without sarcasm and rude remarks would be helpful. There are some very rude and disrespectful people in this forum
You seem to be mixing PHP and JavaScript together. Lots of errors, to many to take time to correct and the logic seems wrong. Tell us what exactly you're trying to do in pseudo code.
The code is unstructured so it makes debugging very difficult. You should certainly learn more structured methods for implementing your code as it will help you immensely as you progress into larger projects. In the meantime however, what I typically do if I just can't see where the error is, I will strip the code to as minimal a section of code as possible and get that to work. Then little by little I add more of the code back in until the error occurs. This will give a clearer indication as to what the offending piece of code is, thus making it much easier to debug and resolve. Hope this helps
try this out <html> <head> <title>Food Survey Results</title> </head> <body> <h1>Your Food Survey</h1> <h2>Poll Results</h2> <script type="text/javascript"> var frmvalidator = new Validator("register"); frmvalidator.EnableOnPageErrorDisplay(); frmvalidator.EnableMsgsTogether(); frmvalidator.addValidation("name","req","Please provide your name"); frmvalidator.addValidation("email","req","Please provide your email address"); frmvalidator.addValidation("email","email","Please provide a valid email address"); frmvalidator.addValidation("username","req","Please provide a username"); frmvalidator.addValidation("password","req","Please provide a password"); function RegisterUser() { if(!isset($_POST['submitted'])) { return false; } $formvars = array(); if(!$this->ValidateRegistrationSubmission()) { return false; } $this->CollectRegistrationSubmission($formvars); if(!$this->SaveToDatabase($formvars)) { return false; } if(!$this->SendUserConfirmationEmail($formvars)) { return false; } $this->SendAdminIntimationEmail($formvars); return true; } </script> <?php if(isset($_POST['submit'])){ $foodquestion = $_POST['foodquestion']; if(!empty($_POST['foodanswer'])){ $foodanswer = $_POST['foodanswer']; echo"<p>You have chosen:<b>".$foodanswer."</b> as your favorite food!</p>"; } else { $foodanswer = FALSE; echo"<p><font color='red'>Please tell us your favorite food!</font></p>"; } $vegiequestion = $_POST['vegiequestion']; if(!isset($_POST['vegieanswer'])){ $vegieanswer = FALSE; echo "<p><font color='red'><b>Please answer the question!</b></font> </p>"; } else { $vegieanswer = $_POST['vegieanswer']; echo"<p><font color='navy'>You checked:<b>"; foreach($vegieanswer as $v){ echo $v."|"; } } echo"</b></font></p>"; $icecreamquestion = $_POST['icecreamquestion']; if(!isset($_POST['icecreamanswer'])){ $icecreamanswer = FALSE; echo"<p><font color='red'><b>Please answer the question!</b></font></p>"; }else{ $icecreamanswer = $_POST['icecreamanswer']; switch($icecreamanswer){ case 'Yes': echo"<p><font color='navy'>You said that you<b><font color='green'> do </font></b>like mint chocolate chip ice cream!</font></p>"; break; case'No': echo"<p><font color='navy'>You said taht you <b>DO NOT</b> like mint chocolate chip ice cream!</font></p>"; break; } } $careerquestion = $_POST['careerquestion']; $careeranswer = $_POST['careeranswer']; if($careeranswer == 'none'){ $careeranswer = FALSE; echo "<p><font color='red'><b>Please answer the question!</b></font></p>"; } else { $careeranswer = $_POST['careeranswer']; echo"<p><font color='navy'>You answered that kids mostly aspire to be a(n) ".$careeranswer."!</font></p>"; } $experiencequestion = $_POST['experiencequestion']; if(!empty($_POST['experienceanswer'])){ $experienceanswer = $_POST['experienceanswer']; echo"<p><font color='navy'>Your favorite experience is " .$experienceanswer."!</font> </p>"; } else { $experienceanswer = FALSE; echo"<p><font color='red'><b>There was an error, please try your response again!</b></font></p>"; } if ($foodanswer != FALSE && $vegieanswer != FALSE && $icecreamanswer != FALSE && $careeranswer != FALSE && $experienceanswer != FALSE) { $newV = implode(' | ',$vegieanswer); $body = "<html><head></head><body>Hi Joe Randolph!<br />Your poll has just been completed. Here are the results:<br /><br /> 1. " . $foodquestion . "<br /> Answer: " . $foodanswer . "<br /><br /> 2. " . $vegiequestion . "<br />Answer: " . $newV . "<br /><br /> 3. " . $icecreamquestion . "<br />Answer: " . $icecreamanswer . "<br /><br /> 4. " . $careerquestion . " <br />Answer: " . $careeranswer . "<br /><br /> 5. " . $experiencequestion . "<br /> Answer: " . $experienceanswer . "<br /></body></html>"; $headers = "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1\n" . "From: Your Survey webby@creativewebsolutions.net"; $to = 'webby@creativewebsolutions.net'; $subject = 'Poll Results'; mail ($to, $subject, $body, $headers); echo "<h2>Your information has been sent to the owner of the survey. Thank you for participating!"; } else { echo "<p><font color='red'><b>Your information could not be sent because of one or more errors. Please try again.</b></font></p>"; } } ?> </body> </html> Code (markup):
The problem that I found while having a quick look at your code is a misplaced closing brace. In this line: //.... if(isset($_POST['submit'])){ } // <--- you have closed it just after opening it. See ? $foodquestion = $_POST['foodquestion']; //.... PHP: Remove that closing brace and add it in here, ie. just before the closing tag of PHP: //... } // <--- place it here ?> </body> </html> PHP: