neverknown Posted August 30, 2017 Share Posted August 30, 2017 I'am making a message system with only username and password. I use a old script but when i remove this line:if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))i receive this error:Parse error: syntax error, unexpected 'else' (T_ELSE) in .....\message\sign_up.php on line 66If i don't remove this line i'll get the message on the signup page like:Notice: Undefined index: email in ....\message\sign_up.php on line 30The email you entered is not valid.Original code:<?phpinclude('config.php');?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href="<?php echo $design; ?>/style.css" rel="stylesheet" title="Style" /><title>Sign up</title></head><body><?php//We check if the form has been sentif(isset($_POST['username'], $_POST['password'], $_POST['passverif']) and $_POST['username']!=''){//We remove slashes depending on the configurationif(get_magic_quotes_gpc()){$_POST['username'] = stripslashes($_POST['username']);$_POST['password'] = stripslashes($_POST['password']);$_POST['passverif'] = stripslashes($_POST['passverif']);}//We check if the two passwords are identicalif($_POST['password']==$_POST['passverif']){//We check if the password has 6 or more charactersif(strlen($_POST['password'])>=6){//We check if the email form is validif(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])){//We protect the variables$username = mysql_real_escape_string($_POST['username']);$password = mysql_real_escape_string($_POST['password']);//We check if there is no other user using the same username$dn = mysql_num_rows(mysql_query('select id from users where username="'.$username.'"'));if($dn==0){//We count the number of users to give an ID to this one$dn2 = mysql_num_rows(mysql_query('select id from users'));$id = $dn2+1;//We save the informations to the databseif(mysql_query('insert into users(id, username, password) values ('.$id.', "'.$username.'", "'.$password.'")')){//We dont display the form$form = false;?><div class="message">You have successfuly been signed up. You can log in.<br /><a href="connexion.php">Log in</a></div><?php}else{//Otherwise, we say that an error occured$form = true;$message = 'An error occurred while signing up.';}}else{//Otherwise, we say the username is not available$form = true;$message = 'The username you want to use is not available, please choose another one.';}}else{//Otherwise, we say the email is not valid$form = true;$message = 'The email you entered is not valid.';}}else{//Otherwise, we say the password is too short$form = true;$message = 'Your password must contain at least 6 characters.';}}else{//Otherwise, we say the passwords are not identical$form = true;$message = 'The passwords you entered are not identical.';}}else{$form = true;}if($form){//We display a message if necessaryif(isset($message)){echo '<div class="message">'.$message.'</div>';}//We display the form?><div class="content"><form action="sign_up.php" method="post">Please fill the following form to sign up:<br /><div class="center"><label for="username">Username</label><input type="text" name="username" value="<?php if(isset($_POST['username'])){echo htmlentities($_POST['username'], ENT_QUOTES, 'UTF-8');} ?>" /><br /><label for="password">Password<span class="small">(6 characters min.)</span></label><input type="password" name="password" /><br /><label for="passverif">Password<span class="small">(verification)</span></label><input type="password" name="passverif" /><br /><input type="submit" value="Sign up" /></div></form></div><?php}?></body></html>Could anyone help me out please? Quote Link to comment https://forums.phpfreaks.com/topic/304807-recieving-error-php/ Share on other sites More sharing options...
requinix Posted August 30, 2017 Share Posted August 30, 2017 Where is the email field? Quote Link to comment https://forums.phpfreaks.com/topic/304807-recieving-error-php/#findComment-1550439 Share on other sites More sharing options...
Solution Sepodati Posted August 30, 2017 Solution Share Posted August 30, 2017 You can't remove the if() condition and leave the related "else" code. 1 Quote Link to comment https://forums.phpfreaks.com/topic/304807-recieving-error-php/#findComment-1550441 Share on other sites More sharing options...
neverknown Posted August 30, 2017 Author Share Posted August 30, 2017 The field for the email is removed already. I want to sign up with username and password only not with email. This is an old script where email is required but i try to remove it. When i remove this line (the email check : if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])) then i receive the error : Parse error: syntax error, unexpected 'else' (T_ELSE) in .....\message\sign_up.php on line 66 Quote Link to comment https://forums.phpfreaks.com/topic/304807-recieving-error-php/#findComment-1550443 Share on other sites More sharing options...
requinix Posted August 30, 2017 Share Posted August 30, 2017 Then what Sepodati said is your next step. Quote Link to comment https://forums.phpfreaks.com/topic/304807-recieving-error-php/#findComment-1550444 Share on other sites More sharing options...
neverknown Posted August 30, 2017 Author Share Posted August 30, 2017 Thank u very much, i figured it out. // before the if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email'])) And a double // in front of the else on line 66 :happy-04: Quote Link to comment https://forums.phpfreaks.com/topic/304807-recieving-error-php/#findComment-1550445 Share on other sites More sharing options...
requinix Posted August 30, 2017 Share Posted August 30, 2017 That is incorrect. What happens when you enter a valid username and password? Quote Link to comment https://forums.phpfreaks.com/topic/304807-recieving-error-php/#findComment-1550448 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.