Need help identifying PHP code syntax error for a form I created for my website.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • P Kerr
    New Member
    • Jan 2011
    • 1

    #1

    Need help identifying PHP code syntax error for a form I created for my website.

    I am new to PHP and have written the following php code for an entry form on my website:

    if ($_FILES['photo']['error'] == 0) {
    // Move the file to the target upload folder
    $target = WS_UPLOADPATH . $photo;
    if (move_uploaded_ file($_FILES[('photo']['tmp_name'], $target)) {
    // Connect to the database
    $dbc = mysqli_connect( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);


    // Write the data to the database
    $query = "INSERT INTO contest_list (first_name, last_name, street_address, city, state, zip_code, " . "daytime, mobile, weight, feet, inches, email, birthdate, comments, photo') " .
    "VALUES (0, '$first_name', '$last_name', '$street_addres s', '$city', '$state', '$zip_code', " . "'$daytime' , '$mobile', '$weight', '$feet', '$inches', '$email', '$birthdate', " .
    "'$comments ', '$photo')";


    $result = mysqli_query($d bc, $query)
    or die('Error querying database.');


    // Confirm success with the user

    echo '<p>Thanks for participating in the Weight Shop's "New You" contest. </p>';

    mysqli_close($d bc);

    }

    else {

    echo '<p>Sorry, there was a problem uploading your photo image.</p>';

    }
    }
    }

    When I view the code in a browser I get the following error message:

    Parse error: syntax error, unexpected T_ENCAPSED_AND_ WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

    The error is said to be in this line of code:
    if ($_FILES['photo']['error'] == 0) {
    above.

    Will you please assist me?
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #2
    First, use code tags. Second, give us the full error (including the line number, but you can remove the file path). Third, post the code BEFORE and up to the error. Usually an error like that happens before the line it says it happens on. Example:

    Code:
    <?php
    $str = "something"
    echo $str;
    ?>
    Error:

    Parse error: syntax error, unexpected T_ECHO in [file] on line 3

    The error is actually on line 2, where I left out the ending semicolon. PHP is trying to tell me that line 3 contains an unexpected echo, which it does, because it's expecting me to end line 2 with a semicolon.

    Post 5 lines of code before the line number in the error message, including that line, so in total you should have 6 lines.

    Comment

    Working...