Registration form sytax error on line 13

Discussion in 'PHP' started by webby68, May 21, 2012.

  1. #1
    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:
     
    webby68, May 21, 2012 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    Is that how your school taught you to code?
     
    NetStar, May 21, 2012 IP
  3. webby68

    webby68 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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
     
    webby68, May 22, 2012 IP
  4. HostPlanz

    HostPlanz Well-Known Member

    Messages:
    449
    Likes Received:
    34
    Best Answers:
    4
    Trophy Points:
    130
    #4
    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.
     
    HostPlanz, May 22, 2012 IP
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #5
    It was a question because it is a very dated approach.
     
    NetStar, May 22, 2012 IP
  6. DaySeven

    DaySeven Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    2
    Trophy Points:
    0
    #6
    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
     
    DaySeven, May 22, 2012 IP
  7. Macaua

    Macaua Greenhorn

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    13
    #7
    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):
     
    Macaua, May 23, 2012 IP
  8. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #8
    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:
     
    akhileshbc, May 27, 2012 IP
  9. webby68

    webby68 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thank you I have started doing that.
     
    webby68, May 30, 2012 IP