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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.