frijole Posted May 15, 2008 Share Posted May 15, 2008 I am getting an error that looks like this: Parse error: syntax error, unexpected T_IF in /home/thinksna/public_html/register.php on line 19 Is there a way to make this work? Here is the code: <?php //this script registers a new user. require_once 'dBconnect.php'; require_once 'functions.php'; if (isset($_POST['register'])) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $rePass = $_POST['rePass']; $query = 'SELECT * FROM users WHERE user_id="$userName"'; $insertUser = 'INSERT INTO users VALUES ($userName, $pass)'; $errors[] = '' if (empty($userName) || empty($pass) || empty($rePass)) { //are any of the fields empty $errors += 'All fields must be filled out.'; } elseif ($pass != $rePass) { //all fileds are filled out, are the values valid? $errors += 'The passwords do not match.'; } elseif (strlen($pass) < 4 || > 12) { //check if username is too long or too short $errors += 'You password must be between 4 and 12 characters long.'; } elseif (strlen($userName) < 4 || > 12) { //check if username is too long or too short $errors += 'You username must be between 4 and 12 characters long.'; } elseif (preg_replace('/[\w ]/', '', $userName) { //check for invalid characters in the username $errors += 'Your username may only contain letters, numbers, or underscores'; } else { //check if username already exists $result = mysql_query($query) or die('Connection Error.'); if (mysql_num_rows($result) > 0) { $errors += 'That username is already taken.'; } else { //add user to the database mysql_query($insertUser) or die('Connection Error.'); echo 'You have been added! sign-in and enjoy.'; } } else { //show form and errors if applicable showRegisterForm($errors); } Quote Link to comment Share on other sites More sharing options...
redarrow Posted May 15, 2008 Share Posted May 15, 2008 My god had a real old good bash at this one here you go try it good luck.... <?php //this script registers a new user. require_once 'dBconnect.php'; require_once 'functions.php'; if (isset($_POST['register'])) { //if the form has been submitted $userName = $_POST['user']; $pass = $_POST['pass']; $rePass = $_POST['rePass']; $query = 'SELECT * FROM users WHERE user_id="$userName"'; $insertUser = 'INSERT INTO users VALUES ($userName, $pass)'; $errors[] = ''; if ( empty($userName) || empty($pass) || empty($rePass) ) { //are any of the fields empty $errors += 'All fields must be filled out.'; } elseif ($pass != $rePass) { //all fileds are filled out, are the values valid? $errors += 'The passwords do not match.'; } elseif (strlen($pass) < 4 || strlen($pass) > 12) { //check if username is too long or too short $errors += 'You password must be between 4 and 12 characters long.'; } elseif (strlen($userName) < 4 || strlen($userName) > 12) { //check if username is too long or too short $errors += 'You username must be between 4 and 12 characters long.'; } elseif (preg_replace('/[\w]/','', $userName)) { //check for invalid characters in the username $errors += 'Your username may only contain letters, numbers, or underscores'; } else { //check if username already exists $result = mysql_query($query) or die('Connection Error.'); if (mysql_num_rows($result) > 0) { $errors += 'That username is already taken.'; } else { //add user to the database mysql_query($insertUser) or die('Connection Error.'); echo 'You have been added! sign-in and enjoy.'; } if($errors){ //show form and errors if applicable showRegisterForm($errors); } } } ?> Quote Link to comment Share on other sites More sharing options...
zq29 Posted May 15, 2008 Share Posted May 15, 2008 You're missing the semi-colon from the end of: $errors[] = '' Quote Link to comment Share on other sites More sharing options...
frijole Posted May 15, 2008 Author Share Posted May 15, 2008 My god had a real old good bash at this one here you go try it good luck.... Thanks for the help. Can you show me what you have changed? I don't see it. Quote Link to comment 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.