If-else condition not working...
Posted: Mon Dec 22, 2008 11:58 am
Hello all...
I have a little piece of code here that has a few nested if-else conditions... it's working fine on all the conditions, but the condition which checks for previously registered users is not working... can you please point out the error in this? Here's my code...
My problems is apparently from line no. 19...
I have a little piece of code here that has a few nested if-else conditions... it's working fine on all the conditions, but the condition which checks for previously registered users is not working... can you please point out the error in this? Here's my code...
Code: Select all
$regUserId=$_POST['regUserId'];
$register=$_POST['regSubmit'];
//check if register button is clicked
if(isset($register)){
$regPWord=$_POST['regPWord'];
$regPWordConfirm=$_POST['regPWordConfirm'];
$name=$_POST['regName'];
$phone=$_POST['regPhone'];
$email=$_POST['regEmail'];
//check if any of the fields are empty
if(empty($name) || empty($phone) || empty($email) || empty($regPWord) || empty($regPWordConfirm)){
echo 'Please don\'t leave any fields empty.<br /><br />';
}else{
//check if the passwords don't match
if($regPWord!=$regPWordConfirm){
echo 'The Passwords don\'t match.<br /><br />';
}else{
//check if the user name exists in the database already
$checkForTwins=@mysql_query("select id from users where userId='".$regUserId."'");
//if the check isn't empty, the name was taken before
if(!empty($checkForTwins)){
echo 'Sorry. That username is already in use. Please try a different name.';
}else{
//start a session
session_start();
//connect to mysql database server
$connect=@mysql_connect('localhost','root');
//check if there's an error in connecting
if(!$connect){
echo 'We are sorry, but there is an error with the server. Please try again later.<br /><br />';
echo mysql_error();
exit();
}
//use the required database
$selectDb=@mysql_query('use talentvisions');
//check if there's an error in using the db
if(!$selectDb){
echo 'We are sorry, but there\'s an error in using the required database. Please try again later.<br /><br />';
echo mysql_error();
exit();
}
//generate unique id string
$uniqId=str_replace(".","",uniqid(microtime(true),true).$_SERVER['REMOTE_ADDR']);
//if user id don't exist, enter the given data into the database
$regPWordMd5=md5($regPWord);
$enterData=@mysql_query("insert into users (userId,pWord,name,phone,email,uniqId) values ('$regUserId', '$regPWordMd5', '$name', '$phone', '$email', '$uniqId')");
//check if there's an error with entering the data
if(!$enterData){
echo 'Sorry, but there was an error while entering the data into the database, please try again later.';
}
//store the uniqid for a session
$_SESSION['uniqId']=$uniqId;
//send user to payment type
header('location:choosePayType.php');
}
}
}
}