Parse error: syntax error, unexpected T_VARIABLE in /home/cre8tiv1/public_html/cs250_

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

  1. #1
    I have been searching this code and I can't determine for the life of me why this isn't working. Did I forget to do something in the validation? The error is at line 75 and the "if else" statement begins with line 69.

    if($foodanswer!=FALSE&&$vegieanswer!=FALSE&&
    $icecreamanswer!=FALSE&&$careeranswer!=FALSE&&
    $experienceanswer!=FALSE){
    $newV = implode('|',$vegieanswer);
    $to = 'youremail@yourdomain.com'
    //$subject = 'Poll Results'
    $body = "<html><head></head><body>Hi Your Name!<br/>Your poll has just been completed. Here are the results:<br/><br/>" . $foodquestion . "<br/>
    Answer: " . $foodanswer . "<br/><br/> " . $vegiequestion . "<br/>Answer: " . $newV . "<br/><br/> " . $icecreamquestion . "<br/>Answer: " . $icecreamanswer . "<br/><br/> " . $careerquestion . "
    <br/> Answer: " . $careeranswer . "<br/><br/> " . $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 donotreply@yourdomain.com";
    mail($to, $subject, $body, $headers);
    echo"<h2>Your information has been sent to the owner of the survey. Thank you for participating!</h2>";
    } 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>";
    }
    ?>
     
    webby68, May 18, 2012 IP
  2. kulik

    kulik Member

    Messages:
    162
    Likes Received:
    18
    Best Answers:
    1
    Trophy Points:
    45
    #2
    There is no if else statement, and also not 75 lines of code posted sooo...
     
    kulik, May 18, 2012 IP
  3. rmacd

    rmacd Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    Please re-post your source with the 'code' tag, which you'll find in the advanced post options.

    R
     
    rmacd, May 18, 2012 IP
  4. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #4
    Here's some free advise, learn how to write cleaner code ;) In any case, there's only one syntax error in that snippet. You're missing a semicolon.

    [COLOR=#111111]$to = 'youremail@yourdomain.com'
    Code (markup):
    [/COLOR]
     
    Alex Roxon, May 18, 2012 IP
  5. rmacd

    rmacd Greenhorn

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #5
    You've more patience than I do :eek:
     
    rmacd, May 18, 2012 IP
  6. webby68

    webby68 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank you Alex for paying attention to what I was asking. Thanks for all the other replies and trying to help from all others. I am new to php, this is my first quarter in college and just learning it.

    Alex, the semi colon was the fix. I just plum overlooked it. Thanks so much! I'm looking forward to much more conversation in this forum.
     
    webby68, May 18, 2012 IP
  7. webby68

    webby68 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    This is the source code for my survey.php that is my project for class. If you run it, the output works wonderfully, and as was pointed out, it may not be the cleanest code, but I am just learning.

    My question is, what code could I use to create a "clear" button so it would clear the output for a clean form?

    <?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 response has been recorded!</font>
        </p>";
        } else {
        $experienceanswer = FALSE;
        echo"<p><font color='red'><b>Please answer the question!</b></font></p>";
        }
        if ($foodanswer != FALSE && $vegieanswer != FALSE &&
    
    $icecreamanswer != FALSE && $careeranswer != FALSE && 
    
    $experienceanswer != FALSE) {
    
    $newV = implode(' | ',$vegieanswer);
    
    $to = 'youremail@yourdomain.com';
    
    //$subject = 'Poll Results'
    
    $body = "<html><head></head><body>Hi Your Name!<br />Your poll has just been completed. Here 
    
    are the results:<br /><br />" . $foodquestion . "<br />
    
    Answer: " . $foodanswer . "<br /><br />" . $vegiequestion . "<br />Answer: " . $newV . "<br /><br />
    
    " . $icecreamquestion . "<br />Answer: " . $icecreamanswer . "<br /><br />" . $careerquestion . "
    
    <br />Answer: " . $careeranswer . "<br /><br />" . $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 donotreply@yourdomain.com";
    
    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>";
    }
    
    
        
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    <title>PHP Pagination</title>
    </head>
    
    
    
    <html>
    <body>
    
    <h1>Your Favorite Foods Survey</h1>
    
    <form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
    1. What is your favorite food?<br/>
    <input type="hidden" name="foodquestion" value="What is your favorite food?"/>
    <input type="text" name="foodanswer" size="60"/><br/><br/>
    
    <br/>
    2. Which of the following do you like the best?<br/>
    <input type="hidden" name="vegiequestion" value="Which of the following do you like the best?"/><br/>
    <input type="checkbox" name="vegieanswer[]" value="Cabbage"/>Cabbage<br/>
    <input type="checkbox" name="vegieanswer[]" value="Brussell Sprouts"/>Brussell Sprouts<br/>
    <input type="checkbox" name="vegieanswer[]" value="Green Beans"/>Green Beans<br/>
    <input type="checkbox" name="vegieanswer[]" value="Green Peppers"/>Green Peppers<br/><br/>
    
    3. Do you like mint chocolate chip flavored ice cream?<br/>
    <input type="hidden" name="icecreamquestion" value="Do you like mint chocolate chip flavored ice cream?"/><br/>
    <input type="radio" name="icecreamanswer" value="Yes"/>Yes<br/>
    <input type="radio" name="icecreamanswer" value="No"/>No
    <br/><br/>
    4. Select the occupation that you think most kids aspire to be: <br/>
    <input type="hidden" name="careerquestion"value="Select the occupation that you think most kids aspire to be:"/>
    
    <select name="careeranswer">
    <option value="none" selected="selected">--Select Occupation--</option>
    <option value="Doctor">Doctor</option>
    <option value="Lawyer">Lawyer</option>
    <option value="Fire Fighter">Fire Fighter</option>
    <option value="Police Officer">Police Officer</option>
    <option value="President of the USA">President of the USA</option>
    <option value="Internet Entrepreneur">Internet Entrepreneur</option>
    </select>
    <br/><br/>
    5. Describe your happiest experience: <br/>
    <input type="hidden" name="careerquestion" value="Describe your happiest experience:"/>
    <textarea name="experienceanswer" rows="10" cols="50"></textarea>
    <input type="submit" name="submit" value="Submit Form" />
    </form>
    </body>
    </html>
    
    Code (markup):
     
    webby68, May 18, 2012 IP
  8. webby68

    webby68 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok, I found the <input type="reset" value="Reset" /> that works well for clearing the form. However, if you run the code in a page you will see that the output is at the top of the page. I don't want to just reset the form, I want to clear the output at the top of the page so that it is blank and will output fresh and new each time the submit button is clicked.
     
    webby68, May 18, 2012 IP
  9. webby68

    webby68 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I figured it out, I just created a separate page for the output.
     
    webby68, May 19, 2012 IP