Jump to content

check sql record with while?


bobocheez

Recommended Posts

Hey,

I'm trying to check if a username is unique, but for some reason none of the methods that I've looked up seem to work.

 

I'm aiming for the code to check if a username is unique, and if get the user to input the name again.

 

$get = "SELECT `i` FROM `m` WHERE `i`=\"$r\"";
$checkResults = mysql_query($getRandomness);
while(mysql_num_row($checkResults) > 0)
{
  //some code...
  //check again
	$get = "SELECT `i` FROM `m` WHERE `i`=$r";
	$checkResults = mysql_query($get);
}

 

The error comes from the while line, but it comes up during the first check because the record is empty.

This is the error:

"Fatal error: Call to undefined function mysql_num_row()"

Link to comment
Share on other sites

Heres the version I use for usename and password

 

if (!isset($user) || !isset($pass)|| empty($user) || empty($pass)) {header( "Location: $loc/login.php" );}

else{
$result=mysql_query("select * from admin where username='$user' AND password='$pass'");
$rowCheck = mysql_num_rows($result);

if($rowCheck > 0){
while($row = mysql_fetch_array($result)){
	session_start();
	$_SESSION['user'] = $_POST['username'];
	$_SESSION['time'] = $time;}
	header( "Location: adminindex.php" );

}else {

header( "Location: $loc/login.php?action=invalid" );}
}

 

Looks like yours just doesn't know what to do if its empty first.

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.