Webwonder Posted March 7, 2008 Share Posted March 7, 2008 I'm new to programming and I need some help. This is the error I'm getting: Parse error: syntax error, unexpected T_VARIABLE in /do_reg.php on line 4 What all looks wrong with this scipt and what is causing the error on line 4? I'm testing this on my home machine, there is no password. <?php $host='localhost'; $dbuser='root'; $dbpass=''; $dbname='user'; $connection=mysql_connect($host, $dbuser, $dbpass); $db=mysql_select_db($dbname, $connection); //grab data from form $user=$_POST['username']; $pass=$_POST['password']; $pass_conf=$_POST['pass_conf']; $email=$_POST['email']; $ip=$_POST['ip']; if ($user==false || $pass==false || $pass_conf==false || $email==false) echo "Please fill in all the required fields."; else if ($pass!=$pass_conf) echo "Incorrect password."; else $connection=mysql_connect($host, $dbuser, $dbpass); $db=mysql_select_db($dbname, $connection); $sql="INSERT INTO user(username,password,email,ip) VALUES ($user, $pass, $email, $ip)"; $result=mysql_query($sql); echo "Registration Successful!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/94939-cant-figure-out-why-im-getting-unexpected-t_variable-syntax-error/ Share on other sites More sharing options...
Daniel0 Posted March 7, 2008 Share Posted March 7, 2008 I'm not sure about the error, there is nothing wrong around line 4 in the code you posted. There is, however, another problem. At the else, seeing as you didn't use any curly brackets, only the following line will belong to that else and the lines after that will be outside the if-else if-else. Quote Link to comment https://forums.phpfreaks.com/topic/94939-cant-figure-out-why-im-getting-unexpected-t_variable-syntax-error/#findComment-486319 Share on other sites More sharing options...
conker87 Posted March 7, 2008 Share Posted March 7, 2008 Could be the no quotes? $sql="INSERT INTO user(username,password,email,ip) VALUES ('$user', '$pass', '$email', '$ip')"; Also, why are you connecting to your db twice? Quote Link to comment https://forums.phpfreaks.com/topic/94939-cant-figure-out-why-im-getting-unexpected-t_variable-syntax-error/#findComment-486320 Share on other sites More sharing options...
Webwonder Posted March 7, 2008 Author Share Posted March 7, 2008 Ok, it was the missing brackets causing the problem. Thanks! I'm just beginning to understand this stuff, I'll probably be posting here a lot more for now on. Quote Link to comment https://forums.phpfreaks.com/topic/94939-cant-figure-out-why-im-getting-unexpected-t_variable-syntax-error/#findComment-486334 Share on other sites More sharing options...
Webwonder Posted March 7, 2008 Author Share Posted March 7, 2008 Could be the no quotes? $sql="INSERT INTO user(username,password,email,ip) VALUES ('$user', '$pass', '$email', '$ip')"; Also, why are you connecting to your db twice? Thanks conker87, those are two other problems I've fixed now. Quote Link to comment https://forums.phpfreaks.com/topic/94939-cant-figure-out-why-im-getting-unexpected-t_variable-syntax-error/#findComment-486368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.