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
https://forums.phpfreaks.com/topic/227828-check-sql-record-with-while/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.