Jump to content

Problem with if statement embedded inside another if statement


frijole

Recommended Posts

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);

} 

Link to comment
Share on other sites

 

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);

}
 }
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.