Jump to content

unexpected T_VARIABLE


cameeob2003

Recommended Posts

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

[code]<?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
{
?>[/code]

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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

Here is line 45:

[code]<?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"
{

?>[/code]

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

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

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

Here is line 45:

[code]<?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());
}
?>[/code]

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]
Link to comment
Share on other sites

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:

[code]<?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());
}
?>[/code]
Link to comment
Share on other sites

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) [snapback]388586[/snapback][/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:

[code]<?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());
}
?>[/code]
[/quote]
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.