Web Design Forum: Unexpected T_VARIABLE - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Unexpected T_VARIABLE Rate Topic: -----

#1 User is offline   Ash Scott 

  • Competition Manager
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,416
  • Joined: 25-May 10
  • Reputation: 53
  • Gender:Male
  • Location:Kent
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 29 January 2012 - 02:42 PM

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
0

#2 User is online   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 29 January 2012 - 02:45 PM

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
0

#3 User is offline   Ash Scott 

  • Competition Manager
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,416
  • Joined: 25-May 10
  • Reputation: 53
  • Gender:Male
  • Location:Kent
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 29 January 2012 - 02:47 PM

View PostJay Gilford, on 29 January 2012 - 02:45 PM, said:

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
0

#4 User is online   Jay Gilford 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,105
  • Joined: 11-October 09
  • Reputation: 185
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 29 January 2012 - 02:50 PM

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
0

#5 User is offline   Ash Scott 

  • Competition Manager
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,416
  • Joined: 25-May 10
  • Reputation: 53
  • Gender:Male
  • Location:Kent
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 29 January 2012 - 02:52 PM

View PostJay Gilford, on 29 January 2012 - 02:50 PM, said:

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
0

#6 User is offline   Ash Scott 

  • Competition Manager
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,416
  • Joined: 25-May 10
  • Reputation: 53
  • Gender:Male
  • Location:Kent
  • Experience:Advanced
  • Area of Expertise:Designer/Coder

Posted 29 January 2012 - 02:54 PM

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

#7 User is online   Spitfire 

  • Mighty Pirate™
  • PipPipPipPip
  • Group: Members
  • Posts: 891
  • Joined: 05-February 11
  • Reputation: 189
  • Gender:Male
  • Location:Berkshire
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 29 January 2012 - 03:14 PM

Delete the brace on line 84.

Also on line 88 you've got a brace instead of a bracket for the else if function.
0

#8 User is online   Georgew 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 141
  • Joined: 06-July 10
  • Reputation: 2
  • Gender:Male
  • Location:Surrey
  • Experience:Beginner
  • Area of Expertise:Web Designer

Posted 29 January 2012 - 04:51 PM

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.

This post has been edited by Georgew: 29 January 2012 - 04:53 PM

0

#9 User is offline   webbhost 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 192
  • Joined: 12-May 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 29 January 2012 - 10:30 PM

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] . " = \"\";"); 
        }
} 
?>


This post has been edited by webbhost: 29 January 2012 - 10:33 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users