January 29, 201214 yr 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
January 29, 201214 yr 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
January 29, 201214 yr 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
January 29, 201214 yr 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
January 29, 201214 yr 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
January 29, 201214 yr Author syntax error, unexpected T_ELSE on line 167 is now the error i come across
January 29, 201214 yr Delete the brace on line 84. Also on line 88 you've got a brace instead of a bracket for the else if function.
January 29, 201214 yr 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 January 29, 201214 yr by Georgew
January 29, 201214 yr 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 January 29, 201214 yr by webbhost
Create an account or sign in to comment