Jump to content

[SOLVED] Bad IF Condition


The Little Guy

Recommended Posts

I am using AJAX to  send POST data... it works... but it doesn't work....

 

It sends the variables to the PHP, but when I use php the php, my IF statement isn't working... Why?

 

JavaScript/AJAX:

function getVal(){
var val = '';
if(document.getElementById('fname').value != '')
	val += 'fname='+document.getElementById('fname').value
if(document.getElementById('lname').value != '')
	val += '&lname='+document.getElementById('lname').value
if(document.getElementById('email').value != '')
	val += '&email='+document.getElementById('email').value
if(document.getElementById('userN').value != '')
	val += '&userN='+document.getElementById('userN').value
if(document.getElementById('pass').value != '')
	val += '&pass='+document.getElementById('pass').value
if(document.getElementById('repass').value != '')
	val += '&repass='+document.getElementById('repass').value
if(document.getElementById('passhint').value != '')
	val += '&passhint='+document.getElementById('passhint').value
//return val;
document.write(val);
}
// AJAX FUNCTION
function btnJoin(){
var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
var ajaxRequest;
try{
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			alert("Your Browser Doesn't support AJAX.");
			return false;
		}
	}
}
ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState < 4){
		document.getElementById('replaceJoin').innerHTML = '<div id="joinBox"><div class="joinboxtext">Joining Please Wait...</div></div>';
	}
	if(ajaxRequest.readyState == 4){
		document.getElementById('replaceJoin').innerHTML = ajaxRequest.responseText;
	}
}
va = getVal();
ajaxRequest.open("POST", '/process/join.php', true);
ajaxRequest.setRequestHeader("Content-Type", contentType);
ajaxRequest.send(va);
}

 

PHP:

<?php
include '../incl/includes.php';
$pass_len = strlen($_POST['pass']);
$user_len = strlen($_POST['userN']);
$sql = mysql_query("SELECT * FROM users WHERE user='{$_POST['userN']}' LIMIT 1")or die(mysql_error());
if(mysql_num_rows($sql)==0 ||
	!empty($_POST['fname'])||
	!empty($_POST['lname'])||
	!empty($_POST['email'])||
	!empty($_POST['userN'])||
	!empty($_POST['pass'])||
	!empty($_POST['repass'])||
	$_POST['pass']==$_POST['repass']||
	$pass_len > 5||
	$pass_len < 11||
	$user_len > 3||
	$user_len < 51){
		$string = "abcdefghijklmnopqrstuvwxyz0123456789";
		$auth_code = '';
		for($i=0;$i<25;$i++){
			$pos = rand(0,36);
			$auth_code .= $string{$pos};
		}			

		$fname = addslashes($_POST['fname']);
		$lname = addslashes($_POST['lname']);
		$user = addslashes($_POST['userN']);
		$email = addslashes($_POST['email']);
		$pass = addslashes($_POST['pass']);
		$phint = addslashes($_POST['passhint']);
		$date_reg = date("Y-m-d H:i:s");
		$ip = $_SERVER['REMOTE_ADDR'];
		/*mysql_query("INSERT INTO users(`fname`,`lname`,`email`,`user`,`pass`,`phint`,`date_reg`,`auth_code`,`ip`)
						VALUES('$fname','$lname','$email','$user','".base64_encode($pass)."','$phint','$date_reg','$auth_code','$ip')")or die(mysql_error());
		mkdir("../users/$user");
		mkdir("../users/$user/thumbs");
		unset($_POST);
		$sql = mysql_query("SELECT MAX(id) as id FROM users WHERE ip = '$ip' AND auth_code = '$auth_code' ORDER BY id LIMIT 1");
		$row = mysql_fetch_array($sql);
		include 'process/regEmailFormat.php';
		mail($email,"TzFiles.com Welcomes You",$message,$headers);
		header("Location: success.php");
		exit;*/
		echo '<div id="joinBox"><div class="joinboxtext">User Created!</div>
		<p style="padding:18px;>
			Please Check your email, there will be a activation link for you to follow. 
			This will confirm the account and your email address.
		</p>
		</div>';
}else{
	echo '<div id="joinBox"><div class="joinboxtext">Invalid!</div><p style="padding:18px;>Oops, there was an error, please re-check</p></div>';
}
?>

 

If statement rules:

 

there can NOT be a user in the database with the same name

all $_POST['*'] fields must be filled in ($_POST['passhint'] is optional)

$pass_len must be between 6 and 10 characters

$user_len must be between 4 and 50 characters

 

is there something I am missing?

 

it all ways echos this:

echo '<div id="joinBox"><div class="joinboxtext">User Created!</div>
		<p style="padding:18px;>
			Please Check your email, there will be a activation link for you to follow. 
			This will confirm the account and your email address.
		</p>
		</div>';

 

and only echo's this if the user name is already in the database:

echo '<div id="joinBox"><div class="joinboxtext">Invalid!</div><p style="padding:18px;>Oops, there was an error, please re-check</p></div>';

Link to comment
Share on other sites

oh yeah... if I leave all the fields blank, it echo's out the successful one

 

echo '<div id="joinBox"><div class="joinboxtext">User Created!</div>
		<p style="padding:18px;>
			Please Check your email, there will be a activation link for you to follow. 
			This will confirm the account and your email address.
		</p>
		</div>';

Link to comment
Share on other sites

try this.. long winded but will revele the problem with the if

<?php
$valid = false;
if(mysql_num_rows($sql)==0)
{
	if(!empty($_POST['fname']))
	{
		if(!empty($_POST['lname']))
		{
			if(!empty($_POST['email']))
			{
				if(!empty($_POST['userN']))
				{
					if(!empty($_POST['pass']))
					{
						if(!empty($_POST['repass']))
						{
							if($_POST['pass']==$_POST['repass'])
							{
								if($pass_len > 5)
								{
									if($pass_len < 11)
									{
										if($user_len > 3)
										{
											if($user_len <51)
											{
												$valid = true;
											}else{echo "user over 51";}
										}else{echo "user  Under 3 chars";}
									}else{echo "pass over 11";}
								}else{echo "Pass Under 5 chars";}
							}else{echo "Passwords Don't match";}
						}else{echo "pass Not Set";}
					}else{echo "pass Not Set";}
				}else{echo "userN Not Set";}
			}else{echo "email Not Set";}
		}else{echo "lname Not Set";}
	}else{echo "fName Not Set";}
}else{echo "Name Taken";}

if(!$valid)
{
	die("error");
}
?>

Link to comment
Share on other sites

<?php
if(mysql_num_rows($sql)=="0"||
	!empty($_POST['fname'])&&
	!empty($_POST['lname'])&&
	!empty($_POST['email'])&&
	!empty($_POST['userN'])&&
	!empty($_POST['pass'])&&
	!empty($_POST['repass'])&&
	$_POST['pass']==$_POST['repass']&&
	$pass_len > 5&&
	$pass_len < 11&&
	$user_len > 3&&
	$user_len < 51) { $valid="true";} else { $valid="false";}?>

Link to comment
Share on other sites

to fix your use

 

if(mysql_num_rows($sql)!=0 &&
	!empty($_POST['fname']) &&
	!empty($_POST['lname']) &&
	!empty($_POST['email']) &&
	!empty($_POST['userN']) &&
	!empty($_POST['pass']) &&
	!empty($_POST['repass']) &&
	$_POST['pass']==$_POST['repass'] &&
	$pass_len > 5 &&
	$pass_len < 11 &&
	$user_len > 3 &&
	$user_len < 51){

 

EDIT: note the !=0

(mysql_num_rows($sql)!=0 &&

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.