Jump to content


Photo

unexpected T_VARIABLE


  • Please log in to reply
5 replies to this topic

#1 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 26 June 2006 - 06:59 AM

I am trying to execute the following script when users register in order to add there information to the mysql data base:

<?php

// Set global variables to easier names
$n2puser = $_GET['n2puser'];
$n2ppass = $_GET['n2ppass'];
$n2ppass2 = $_GET['n2ppass2'];
$email = $_GET['email'];
$email2 = $_GET['email2'];
$alias = $_GET['alias'];

// Check for password match
if($n2ppass!==$n2ppass2)
{
    echo "Passwords do not match";
    exit();
}
else
{

// Check for email match
if($email!==$email2)
{
    echo "Email Addresses Do Not Match";
    exit();
}
else
{

// insert new password example
$password = md5($n2ppass);
$sql = "INSERT INTO $tbl_name (password) values ('$password')";

$add_all = 'INSERT INTO $tbl_name (username,alias,email)
values('$n2puser','$alias','$email'');
    mysql_query($add_all) or die(mysql_error());
}
else
{
?>

but i get the following error:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected T_VARIABLE in /homepages/34/d154144477/htdocs/ventgaming/n2p/login/register.php on line 42[/quote]

I have gone over the code but cant figure out what im doing wrong. I am new to this so any help is great.

#2 logu

logu
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts

Posted 26 June 2006 - 07:28 AM

problem is in this sentence

$add_all = 'INSERT INTO $tbl_name (username,alias,email)
values('$n2puser','$alias','$email'');

it should be

$add_all = "INSERT INTO $tbl_name (username,alias,email)
values('$n2puser','$alias','$email')";


try this

Regards logu


#3 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 27 June 2006 - 05:16 PM

Your help worked and i got that error fixed but now i get this one:

Parse error: parse error, unexpected T_ELSE in /homepages/34/d154144477/htdocs/ventgaming/n2p/login/register.php on line 45

Here is line 45:

<?php

// Set global variables to easier names
$n2puser = $_GET['n2puser'];
$n2ppass = $_GET['n2ppass'];
$n2ppass2 = $_GET['n2ppass2'];
$email = $_GET['email'];
$email2 = $_GET['email2'];
$alias = $_GET['alias'];

// Check for password match
if($n2ppass!==$n2ppass2)
{
    echo "Passwords do not match";
    exit();
}
else
{

// Check for email match
if($email!==$email2)
{
    echo "Email Addresses Do Not Match";
    exit();
}
else
{

// insert new password example
$password = md5($n2ppass);
$sql = "INSERT INTO $tbl_name (password) values ('$password')";

$add_all = "INSERT INTO $tbl_name (username,alias,email)
values('$n2puser','$alias','$email')";
    mysql_query($add_all) or die(mysql_error());
}
 else "<-- LINE 45"
{

?>

Im not sure what im supposed to put there because I remove the else and get an error. Any help would be greatly appreciated.

#4 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 27 June 2006 - 05:19 PM

[!--quoteo(post=388561:date=Jun 27 2006, 01:16 PM:name=cameeob2003)--][div class=\'quotetop\']QUOTE(cameeob2003 @ Jun 27 2006, 01:16 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Your help worked and i got that error fixed but now i get this one:

Parse error: parse error, unexpected T_ELSE in /homepages/34/d154144477/htdocs/ventgaming/n2p/login/register.php on line 45

Here is line 45:

<?php

// Set global variables to easier names
$n2puser = $_GET['n2puser'];
$n2ppass = $_GET['n2ppass'];
$n2ppass2 = $_GET['n2ppass2'];
$email = $_GET['email'];
$email2 = $_GET['email2'];
$alias = $_GET['alias'];

// Check for password match
if($n2ppass!==$n2ppass2)
{
    echo "Passwords do not match";
    exit();
}
elseif($email!==$email2)
{
    echo "Email Addresses Do Not Match";
    exit();
}
else
{

// insert new password example
$password = md5($n2ppass);
$sql = "INSERT INTO $tbl_name (password) values ('$password')";

$add_all = "INSERT INTO $tbl_name (username,alias,email)
values('$n2puser','$alias','$email')";
    mysql_query($add_all) or die(mysql_error());
}
?>

Im not sure what im supposed to put there because I remove the else and get an error. Any help would be greatly appreciated.
[/quote]


#5 cameeob2003

cameeob2003
  • Members
  • PipPipPip
  • Advanced Member
  • 79 posts

Posted 27 June 2006 - 05:59 PM

I did that also but now it just says that the last line of my code has errors no matter what. Even if the line is blank it says it has errors. Im not sure what would be casuing this to happen. I think that I didnt end the following code correct but its hard for me to say since im new to PHP. Here is what I curently have written:

<?php

// Set global variables to easier names
$n2puser = $_GET['n2puser'];
$n2ppass = $_GET['n2ppass'];
$n2ppass2 = $_GET['n2ppass2'];
$email = $_GET['email'];
$email2 = $_GET['email2'];
$alias = $_GET['alias'];

if((!$n2puser) || (!$n2ppass) || (!$n2ppass2) || (!$email) || (!email2) || (!alias)){
    echo 'You did not submit the following required information! <br />';
    if(!$n2puser){
        echo "Username is a required field. Please enter it below.<br />";
    }
    if(!$n2ppass){
        echo "Password is a required field. Please enter it below.<br />";
    }
    if(!$n2ppass2){
        echo "Re-Type Password is a required field. Please enter it below.";
    }
    if(!$email){
        echo "Email is a required field. Please enter it below.<br />";
    }
    if(!$email2){
        echo "Re-Type Email is a required field. Please enter it below.<br />";
    }
    if(!$alias){
        echo "Alias is a required field. Please enter it below.<br />";
    }
    include 'register.html';
    exit();
}

// Check for password match
if($n2ppass!==$n2ppass2)
{
    echo "Passwords do not match";
    exit();
}
else
{

// Check for email match
if($email!==$email2)
{
    echo "Email Addresses Do Not Match";
    exit();
}
else
{

# does this user already exist in the database? lets check for that now... 
 $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
 $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$n2puser'");
 
 $email_check = mysql_num_rows($sql_email_check);
 $username_check = mysql_num_rows($sql_username_check);
 
 if(($email_check > 0) || ($username_check > 0)){
     echo "Please fix the following errors: <br />";
     if($email_check > 0){
         echo "<strong>Your email address has already been used by another member in our database. Please use a different Email address!<br />";
         unset($email_address);
     }
     if($username_check > 0){
         echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />";
         unset($username);
     }
     include 'register.html'; // Show the form again!
     exit();
 }      

// insert new password example
$password = md5($n2ppass);
$sql = "INSERT INTO $tbl_name (password) values ('$password')";

$add_all = "INSERT INTO $tbl_name (username,alias,email)
values('$n2puser','$alias','$email')";
    mysql_query($add_all) or die(mysql_error());
}
?>


#6 AV1611

AV1611
  • Members
  • PipPipPip
  • Advanced Member
  • 997 posts

Posted 28 June 2006 - 03:32 PM

You are not nesting your else/if/elseif clauses correctly. Use indentation to keep them staight.

[!--quoteo(post=388586:date=Jun 27 2006, 01:59 PM:name=cameeob2003)--][div class=\'quotetop\']QUOTE(cameeob2003 @ Jun 27 2006, 01:59 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I did that also but now it just says that the last line of my code has errors no matter what. Even if the line is blank it says it has errors. Im not sure what would be casuing this to happen. I think that I didnt end the following code correct but its hard for me to say since im new to PHP. Here is what I curently have written:

<?php

// Set global variables to easier names
$n2puser = $_GET['n2puser'];
$n2ppass = $_GET['n2ppass'];
$n2ppass2 = $_GET['n2ppass2'];
$email = $_GET['email'];
$email2 = $_GET['email2'];
$alias = $_GET['alias'];

if((!$n2puser) || (!$n2ppass) || (!$n2ppass2) || (!$email) || (!email2) || (!alias)){
    echo 'You did not submit the following required information! <br />';
    if(!$n2puser){
        echo "Username is a required field. Please enter it below.<br />";
    }
    if(!$n2ppass){
        echo "Password is a required field. Please enter it below.<br />";
    }
    if(!$n2ppass2){
        echo "Re-Type Password is a required field. Please enter it below.";
    }
    if(!$email){
        echo "Email is a required field. Please enter it below.<br />";
    }
    if(!$email2){
        echo "Re-Type Email is a required field. Please enter it below.<br />";
    }
    if(!$alias){
        echo "Alias is a required field. Please enter it below.<br />";
    }
    include 'register.html';
    exit();
}

// Check for password match
if($n2ppass!==$n2ppass2)
{
    echo "Passwords do not match";
    exit();
}
else
{

// Check for email match
if($email!==$email2)
{
    echo "Email Addresses Do Not Match";
    exit();
}
else
{

# does this user already exist in the database? lets check for that now... 
 $sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
 $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$n2puser'");
 
 $email_check = mysql_num_rows($sql_email_check);
 $username_check = mysql_num_rows($sql_username_check);
 
 if(($email_check > 0) || ($username_check > 0)){
     echo "Please fix the following errors: <br />";
     if($email_check > 0){
         echo "<strong>Your email address has already been used by another member in our database. Please use a different Email address!<br />";
         unset($email_address);
     }
     if($username_check > 0){
         echo "The username you have selected has already been used by another member in our database. Please choose a different Username!<br />";
         unset($username);
     }
     include 'register.html'; // Show the form again!
     exit();
 }      

// insert new password example
$password = md5($n2ppass);
$sql = "INSERT INTO $tbl_name (password) values ('$password')";

$add_all = "INSERT INTO $tbl_name (username,alias,email)
values('$n2puser','$alias','$email')";
    mysql_query($add_all) or die(mysql_error());
}
?>
[/quote]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users