Jump to content

Checking Mysql num rows


Snooble

Recommended Posts

			
<?php 
$check = "SELECT * FROM wmusers where username='".$_SESSION['usernamereg']."' LIMIT 1";
$checkresult = mysql_query($check);
		if(isset($_SESSION['usernamereg']) && strlen($_SESSION['usernamereg'] < "1")){
		echo '<span class="registererror">(Empty) Username</span>';
		}
		elseif(mysql_num_rows($checkresult) != 0){
		echo '<span class="registererror">(Taken) Username</span>';
		}			
		else{
		echo '<span class="register">Username</span>';
		}
		?>

 

I need it to only display "(Taken) Username" when the username is taken. At the moment i get that all the time. I guess i need to add a new condition to the row check? Thank you,

 

Snooble

 

(Heres the checkregister.php ((The page this POST's to)))

<?php 
include 'expire.php';
include 'sessionstartandsql.php';
$_SESSION['usernamereg'] = $_POST['username'];
$_SESSION['passwordreg'] = $_POST['password'];
$_SESSION['emailreg'] = $_POST['email'];
if ($_POST['username'] == NULL){
	header("Location: register.php");}
if ($_POST['password'] == NULL){
	header("Location: register.php");}
if ($_POST['email'] == NULL){
        header("Location: register.php");}
if (!eregi('@', $_SESSION['emailreg'])) {
   		header("Location: register.php");}

$check = "SELECT * FROM wmusers where username='".$_POST['username']."' LIMIT 1";
$checkresult = mysql_query($check);
if(mysql_num_rows($checkresult) != 0)
header("Location: register.php");

$sql = "INSERT INTO wmusers VALUES ('".$_POST['username']."', '".$_POST['password']."', '".$_POST['email']."', '0', '0', '0')";
mysql_query($sql) or die ("Couldn't execute $sql: " . mysql_error()); 

?>

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/41629-checking-mysql-num-rows/
Share on other sites

No, I need a more accurate condition. Your's is the same as mine. At the moment my statement:

 

<?php
		elseif(mysql_num_rows($checkresult) != 0){
		echo '<span class="registererror">(Taken) Username</span>';
		}	
?>

Is always true. I need it to be more accurate so that if the user enters a username that's NOT in the database it executes the ELSE statement. Thanks for the responce nevertheless. Anyone?

 

SNooble

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.