Hey guys, first time posting here but I have a problem... I'm new to PHP and I keep getting this error Parse error: syntax error, unexpected T_ELSE, expecting T_VARIABLE or '$' in D:\Programs\Program Files (x86)\wamp\www\web dev copy\Project\enter.php on line 21 <?php $username=$_POST['username']; $firstname=$_POST['firstname']; $surname=$_POST['surname']; $password=$_POST['password']; $course=$_POST['course']; $email=$_POST['email']; $question=$_POST['question']; $answer=$_POST['answer']; setcookie("user", $username, time()+36000); $con=mysql_connect("localhost","root"); if(!$con) { die('Could not connecct'. mysql_error()); } mysql_select_db("webdev", $con); $query="SELECT * FROM users WHERE username = '$username'"; echo $query; $ else //THIS IS LINE 21 { $sql="INSERT INTO users (username, password, firstname, surname, course, email, question, answer) VALUES ('$_POST[username]', '$_POST[password]', '$_POST[firstname]', '$_POST[surname]', '$_POST[course]', '$_POST', '$_POST[question]', '$_POST[answer]')"; } if(!mysql_query($sql,$con)) { die('error:'. mysql_error()); } header("location: diarypage.php"); ?> If you could help that would be great.
<?php $username=$_POST['username']; $firstname=$_POST['firstname']; $surname=$_POST['surname']; $password=$_POST['password']; $course=$_POST['course']; $email=$_POST['email']; $question=$_POST['question']; $answer=$_POST['answer']; setcookie("user", $username, time()+36000); $con=mysql_connect("localhost","root"); if(!$con) { die('Could not connecct'. mysql_error()); } else //THIS IS LINE 21 { mysql_select_db("webdev", $con); $query="SELECT * FROM users WHERE username = '$username'"; echo $query; $sql="INSERT INTO users (username, password, firstname, surname, course, email, question, answer) VALUES ('$_POST[username]', '$_POST[password]', '$_POST[firstname]', '$_POST[surname]', '$_POST[course]', '$_POST[email]', '$_POST[question]', '$_POST[answer]')"; } if(!mysql_query($sql,$con)) { die('error:'. mysql_error()); } header("location: diarypage.php"); ?> PHP: Thats better. You just had a $ symbol on its own on the line before it was meant to be a } but I've rearranged your code to what I think it should be.