PHP & MySQL Help

Discussion in 'PHP' started by RaschNuts, Jan 18, 2012.

  1. #1
    [TABLE="class: tborder, width: 100%, align: center"]
    [TR="bgcolor: transparent"]
    [TD="class: alt1, bgcolor: #FCFCFC"]I keep getting this error. I am working through an assignment in a PHP MySQL book and new to this. If anyone could help that would be great.

    I inserted dummy words for the password and host name for privacy reasons

    Parse error: syntax error, unexpected T_VARIABLE in /home/content/21/8794321/html/report.php on line 26

    <?php
    $first_name = $_POST['firstname'];
    $last_name = $_POST['lastname'];
    $when_it_happened = $_POST['whenithappened'];
    $how_long = $_POST['howlong'];
    $how_many = $_POST['howmany'];
    $alien_description = $_POST['aliendescription'];
    $what_they_did = $_POST['whattheydid'];
    $fang_spotted = $_POST['fangspotted'];
    $email = $_POST['email'];
    $other = $_POST['other'];

    $dbc = mysqli_connect('hostname','owenfang1','password',' aliendatabase')
    or die('Error connecting to MySQL server.')

    $query = "INSERT INTO aliens_abduction (first_name, last_name, when_it_happened, how_long, " .
    "how_many, alien_description, what_they_did, fang_spotted, other, email) " .
    "VALUES ('$first_name', '$last_name', '$when_it_happened', '$how_long', '$how_many', " .
    "'$alien_description', '$what_they_did', '$fang_spotted', '$other', '$email')";

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

    mysqli_close($dbc);

    echo 'Thanks for submitting the form.<br />';
    echo 'You were abducted ' . $when_it_happened;
    echo ' and were gone for ' . $how_long . '<br />';
    echo 'Number of aliens: ' . $how_many . '<br />';
    echo 'Describe them: ' . $alien_description . '<br />';
    echo 'The aliens did this: ' . $what_they_did . '<br />';
    echo 'Was Fang there? ' . $fang_spotted . '<br />';
    echo 'Other comments: ' . $other . '<br />';
    echo 'Your email address is ' . $email;
    ?>
    [/TD]
    [/TR]
    [/TABLE]
     
    RaschNuts, Jan 18, 2012 IP
  2. vchris

    vchris Greenhorn

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    I think your error is about the variables inside single quotes in your query. If you need the quotes you'll have to do it like this: VALUES ('".$first_name."', '"...
     
    vchris, Jan 18, 2012 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Change:
    or die('Error connecting to MySQL server.')

    to:
    or die('Error connecting to MySQL server.');

    Need to close the line with a semicolon.

    Try using netbeans (http://netbeans.org/downloads/index.html) or another IDE to write code with. They will quickly show you any errors in your code.
     
    Last edited: Jan 18, 2012
    jestep, Jan 18, 2012 IP
  4. RaschNuts

    RaschNuts Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks jestep always the little things.
     
    RaschNuts, Jan 18, 2012 IP
  5. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #5
    your db connection is failure chek it and then load this code
     
    Irfi0009, Jan 19, 2012 IP
  6. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #6
    $dbc = mysqli_connect('hostname','owenfang1','password',' aliendatabase')

    correct
    $dbc = mysql_connect('hostname','owenfang1','password',' aliendatabase')
     
    Irfi0009, Jan 19, 2012 IP
  7. JamesD31

    JamesD31 Peon

    Messages:
    36
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #7
    JinGKing mysqli_connect is still a proper function. Anyways the problem was already solved and it was with a missing ';'
     
    JamesD31, Jan 19, 2012 IP