Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Unexpected T_VARIABLE

Featured Replies

Hi people. Today i had my first crack at PHP, and im getting lots of errors. I cant find the solution to this one though..

 

syntax error, unexpected T_VARIABLE

 

<?php
include_once "scripts/connect_to_mysql.php";

if (isset($_post['firstname'])){

$firstname = $_post['firstname'];
$lastname = $_post['lastname'];
$country = $_post['country'];
$city = $_post['city'];
$town = $_post['town'];
$username = $_post['username'];
$email = $_post['email'];
$confirmemail = $_post['confirmemail'];
$password = $_post['password'];
$confirmpassword = $_post['confirmpassword'];
$website = $_post['website'];
$youtube = $_post['youtube'];
$xfire = $_post['xfire'];

$firstname = stripslashes($firstname);
$lastname = stripslashes($lastname);
$country = stripslashes($country);
$city = stripslashes($city);
$town = stripslashes($town);
$username = stripslashes($username);
$email = stripslashes($email);
$confirmemail = stripslashes($confirmemail);
$password = stripslashes($password);
$confirmpassword = stripslashes($confirmpassword);
$website = stripslashes($website);
$youtube = stripslashes($youtube);
$xfire = stripslashes($xfire);

$firstname = strip_tags($firstname);
$lastname = strip_tags($lastname);
$country = strip_tags($country);
$city = strip_tags($city);
$town = strip_tags($town);
$username = strip_tags($username);
$email = strip_tags($email);
$confirmemail = strip_tags($confirmemail);
$password = strip_tags($password);
$confirmpassword = strip_tags($confirmpassword);
$website = strip_tags($website);
$youtube = strip_tags($youtube);
$xfire = strip_tags($xfire);

$sql_email_check = mysql_query("SELECT email FROM members WHERE email='$email'");
$email_check = mysql_num_rows($sql_email_check);

if ((!$firstname)||(!$lastname)||(!$country)||(!$city)||(!$town)||(!$username)||(!$email)||(!$confirmemail)||(!$password)||(!$confirmpassword)

$errormsg = 'Error: The following information is required<br><br>';

if(!$firstname){
$errormsg = '* First Name';
}
if(!$lastname){
$errormsg = '* Last Name';
}
if(!$country){
$errormsg = '* Country';
}
if(!$city){
$errormsg = '* City';
}
if(!$town){
$errormsg = '* Town';
}
if(!$username){
$errormsg = '* Username';
}
if(!$Email){
$errormsg = '* Email';
}
if(!$confirmemail){
$errormsg = '* Confirm Email';
}
if(!$password){
$errormsg = '* Password';
}
if(!$confirmpassword){
$errormsg = '* Confirm Password';
}

} else if ($email !=$confirmemail){
	$errormsg = 'Error: The emails do not match<br>';
} else if {$password !=$confirmpassword){
	$errormsg = 'Error: Passwords do not match<br>';
}else if ($email_check > 0){
	$errormsg = 'Error: Email is already in use<br>';

}else{

$firstname = mysql_real_escape_string($firstname);
$lastname = mysql_real_escape_string($lastname);
$country = mysql_real_escape_string($country);
$city = mysql_real_escape_string($city);
$town = mysql_real_escape_string($town);
$username = mysql_real_escape_string($username);
$email = mysql_real_escape_string($email);
$confirmemail = mysql_real_escape_string($confirmemail);
$password = mysql_real_escape_string($password);
$confirmpassword = mysql_real_escape_string($confirmpassword);
$website = mysql_real_escape_string($website);
$youtube = mysql_real_escape_string($youtube);
$xfire = mysql_real_escape_string($xfire);

$firstname = eregi_replace("`","",$firstname);
$lastname = eregi_replace("`","",$lastname);
$country = eregi_replace("`","",$country);
$city = eregi_replace("`","",$city);
$town = eregi_replace("`","",$town);
$username = eregi_replace("`","",$username);
$email = eregi_replace("`","",$email);
$confirmemail = eregi_replace("`","",$confirmemail);
$password = eregi_replace("`","",$password);
$confirmpassword = eregi_replace("`","",$confirmpassword);

$website = eregi_replace("http://","",$website);
$youtube = eregi_replace("http://www.youtube.com/user/","",$youtube);
$xfire = eregi_replace("`","",$xfire);

$db_password = md5($password);

$sql = mysql_query("INSERT INTO members (firstname,lastname,country,city,town,username,email,password,website,youtube,xfire)
VALUES('$firstname','$lastname','$country','$city','$town','$username','$email','$db_password','$website','$youtube','$xfire')")
or die (mysql_error());

$id = mysql_insert_id();

mkdir("members/$id",0755);

$to = "email";
$from = "admin@fragtalk.org";
$subject = "FragTalk Account Activation";
$message = "Hi $firstname,

You recently signed up for an account on FragTalk. All you now need to do is activate your account. Click the link below to activate it.

http://www.fragtalk.org/activation.php?id=$id&sequence=$db_password
If the above link is not an active link, please copy and paste it into your browsers address bar.

After your activation is successful, you can log in using the following information:
Username:$username
Password:$password

We look forward to seeing you on our website!
Kind Regards,
Frag Talk";

$headers = "From: $from\r\n";
$headers = "content-type: text\r\n";
$to = "$to";

mail($to,$subject,$message,$headers);

$msgToUser = "<h2>One Last Step - Activate Through Email</h2><br><h4>Okay $firstname, one last step left to verify your email identity.</h4><br>In a moment, you will receive an email from us, with activation instructions  enclosed. If you don't get the email, contact the site admin.";

include_once "msgToUser.php";

exit();

}


} else {

$errormsg = "Fields marked with an [*] are required.";
$firstname = "";
$lastname = "";
$country = "";
$city = "";
$town = "";
$username = "";
$email = "";
$confirmemail = "";
$password = "";
$confirmpassword = "";
$website = "";
$youtube = "";
$xfire = "";
}
?>

 

Does anyone have an idea of what it could be?

 

Regards,

Ash

Line 51 is missing a ) at the end of it (the long IF line). Also, note eregi is a deprecated function and shouldn't be used at all. This script is hugely out of date

  • Author

Line 51 is missing a ) at the end of it (the long IF line). Also, note eregi is a deprecated function and shouldn't be used at all. This script is hugely out of date

 

Okay what should i use instead of eregi??

 

Im not writing it out again, took me 5 hours as it is

5 hours? you need to use preg_replace instead, although if this is just for practice, don't worry about it, but be aware and take a look at more in date material

  • Author

5 hours? you need to use preg_replace instead, although if this is just for practice, don't worry about it, but be aware and take a look at more in date material

 

yeah well i have never seen php before in this much detail lol, so it took me forever :S

  • Author

syntax error, unexpected T_ELSE on line 167 is now the error i come across -_-

if (isset($_post['firstname'])){ 
if () {
} else if (){

} else if (){

} else if (){

} else {

}
} else {

}

 

Like that.

 

When you get around to it: MD5 or SHA1 that password the moment you get it and don't repeat it back to the user.

Edited by Georgew

couldn't help but to notice a big load of code there which is very repeated... I thought I'd give you my 2 cents.. Im not a pro PHP'er but I like to think I know a bit so heres my take on this.. you could highly reduce the amount of code you are having to write by using arrays and eval.. As follows:

 

(May not be a working example but it gives you a rough idea of how you can reduce the amount of time its taking to do a big task like this..)

 

If you can get your head around working with arrays end eval() (evaluate) then you can save yourself tonnes of time:

 

*Remember not a working exmaple so don't try to copy and paste this is it will most likely cause your php file to die.

 

 

<?php 
include_once "scripts/connect_to_mysql.php"; 

if (isset($_post['firstname'])){ 

       $array = array("firstname", "lastname", "country", "city", "town", "username", "email", "confirmemail", "password", "confirmpassword", "website", "youtube", "xfire");

       for ($x = 0; $x < count($array); $x++){
           eval ("$" . $array[$x] . " = strip_tags(stripslashes($_POST['" . $array[$x] . "']));"); //**gets each item via post, strips slashes and tags
       }
       $sql_email_check = mysql_query("SELECT email FROM members WHERE email='$email'"); 
       $email_check = mysql_num_rows($sql_email_check); 

       if ((!$firstname)||(!$lastname)||(!$country)||(!$city)||(!$town)||(!$username)||(!$email)||(!$confirmemail)||(!$password)||(!$confirmpassword) 
           $errormsg = 'Error: The following information is required<br><br>';
           }
       if(!$firstname){ 
       $errormsg = '* First Name'; 
       } 
       if(!$lastname){ 
       $errormsg = '* Last Name'; 
       } 
       if(!$country){ 
       $errormsg = '* Country'; 
       } 
       if(!$city){ 
       $errormsg = '* City'; 
       } 
       if(!$town){ 
       $errormsg = '* Town'; 
       } 
       if(!$username){ 
       $errormsg = '* Username'; 
       } 
       if(!$Email){ 
       $errormsg = '* Email'; 
       } 
       if(!$confirmemail){ 
       $errormsg = '* Confirm Email'; 
       } 
       if(!$password){ 
       $errormsg = '* Password'; 
       } 
       if(!$confirmpassword){ 
       $errormsg = '* Confirm Password'; 
       } 

       } else if ($email !=$confirmemail){ 
               $errormsg = 'Error: The emails do not match<br>'; 
       } else if {$password !=$confirmpassword){ 
               $errormsg = 'Error: Passwords do not match<br>'; 
       }else if ($email_check > 0){ 
               $errormsg = 'Error: Email is already in use<br>';    
       }else{ 
       for ($x = 0; $x < count($array); $x++){
          eval ("$" . $array[$x] . " = mysql_real_escape_string($" . $array[$x] . ");"); 
       }

       $array2 = array("firstname", "lastname", "country", "city", "town", "username", "email", "confirmemail", "password", "confirmpassword", "xfire");
       for ($x = 0; $x < count($array2); $x++){
          eval ("$" . $array2[$x] . " = eregi_replace(\"`\",\"\", $" . $array2[$x] . ");"); 
       }  
       $website = eregi_replace("http://","",$website); 
       $youtube = eregi_replace("http://www.youtube.com/user/","",$youtube); 

       $db_password = md5($password); 

       $sql = mysql_query("INSERT INTO members (firstname,lastname,country,city,town,username,email,password,website,youtube,xfire) 
       VALUES('$firstname','$lastname','$country','$city','$town','$username','$email','$db_password','$website','$youtube','$xfire')") 
       or die (mysql_error()); 

       $id = mysql_insert_id(); 

       mkdir("members/$id",0755); 

       $to = "email"; 
       $from = "admin@fragtalk.org"; 
       $subject = "FragTalk Account Activation"; 
       $message = "Hi $firstname, 

       You recently signed up for an account on FragTalk. All you now need to do is activate your account. Click the link below to activate it. 

       http://www.fragtalk.org/activation.php?id=$id&sequence=$db_password 
       If the above link is not an active link, please copy and paste it into your browsers address bar. 

       After your activation is successful, you can log in using the following information: 
       Username:$username 
       Password:$password 

       We look forward to seeing you on our website! 
       Kind Regards, 
       Frag Talk"; 

       $headers = "From: $from\r\n"; 
       $headers = "content-type: text\r\n"; 
       $to = "$to"; 

       mail($to,$subject,$message,$headers); 

       $msgToUser = "<h2>One Last Step - Activate Through Email</h2><br><h4>Okay $firstname, one last step left to verify your email identity.</h4><br>In a moment, you will receive an email from us, with activation instructions  enclosed. If you don't get the email, contact the site admin."; 

       include_once "msgToUser.php"; 

       exit(); 

       } 


} else { 
       $errormsg = "Fields marked with an [*] are required."; 
       for ($x = 0; $x < count($array); $x++){
          eval ("$" . $array[$x] . " = \"\";"); 
       }
} 
?>

Edited by webbhost

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.