[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]
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."', '"...
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.
$dbc = mysqli_connect('hostname','owenfang1','password',' aliendatabase') correct $dbc = mysql_connect('hostname','owenfang1','password',' aliendatabase')
JinGKing mysqli_connect is still a proper function. Anyways the problem was already solved and it was with a missing ';'