Jump to content

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

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.