Jump to content

Can't figure out why I'm getting 'unexpected T_VARIABLE syntax error'.


Webwonder

Recommended Posts

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!";
    
?>

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.

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. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.