Page 1 of 1

Checking User Information

Posted: Wed Jan 21, 2004 2:30 pm
by AliasBDI
I have an update page which takes information from a form. It first gathers the variables and then checks the database to make sure the person did not change there username to one that is already in the database.

I did a mere IF statement to do the checking. My problem is, that it is finding the very record of the person who is doing the updating and says that it already exists. Any ideas on how to pull this off more effectively?

Re: Checking User Information

Posted: Wed Jan 21, 2004 3:06 pm
by microthick
AliasBDI wrote:I have an update page which takes information from a form. It first gathers the variables and then checks the database to make sure the person did not change there username to one that is already in the database.

I did a mere IF statement to do the checking. My problem is, that it is finding the very record of the person who is doing the updating and says that it already exists. Any ideas on how to pull this off more effectively?
In the form, create a hidden field that contains the username, called originalUsername or something.

Then, only run the if statement if $username != $originalUsername.

crap...

Posted: Wed Jan 21, 2004 3:30 pm
by AliasBDI
Crap. I'm a newbie. I a bit confused about where to put it... It makes sense though. Here is my code:

Code: Select all

$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
 $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
 $sql_dl_check = mysql_query("SELECT username FROM users WHERE dl='$dl'");

 $email_check = mysql_num_rows($sql_email_check);
 $username_check = mysql_num_rows($sql_username_check);
 $dl_check = mysql_num_rows($sql_dl_check);

 if(($email_check > 0) || ($username_check > 0) || ($dl_check > 0)){
 	echo "Please fix the following errors: <br />";
 	if($email_check > 0)&#123;
 		echo "<strong>Your <b>email address</b> has already been registered by another member in our database. Please submit a different Email address!<br />";
 		unset($email_address);
 	&#125;
 	if($username_check > 0)&#123;
 		echo "The <b>username</b> you have selected has already been registered by another member in our database. Please choose a different Username!<br />";
 		unset($username);
 	&#125;
 	if($dl_check > 0)&#123;
 		echo "The <b>driver's license</b> you have selected has already been registered by another member in our database. Please choose a different License number or contact our customer support in order to reopen your account.!<br />";
 		unset($username);
 	&#125;
 	echo "Please go BACK and try again."; // Show the form again!
 	exit();  // exit the script so that we do not create this account!
 &#125;

Posted: Wed Jan 21, 2004 4:03 pm
by microthick
You could probably just add a simple check here:

Code: Select all

$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'"); 
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'"); 
$sql_dl_check = mysql_query("SELECT username FROM users WHERE dl='$dl'"); 

$email_check = mysql_num_rows($sql_email_check);

// If the updated username is the same as the original
// username, assume that the updated username is safe to use.
// Otherwise, check how many people are using this username.
if ($username == $oldusername) &#123;
     $username_check = 0;
&#125; else &#123;
     $username_check = mysql_num_rows($sql_username_check);
&#125;
$dl_check = mysql_num_rows($sql_dl_check); 

if(($email_check > 0) || ($username_check > 0) || ($dl_check > 0))&#123; 
   echo "Please fix the following errors: <br />"; 
   if($email_check > 0)&#123; 
      echo "<strong>Your <b>email address</b> has already been registered by another member in our database. Please submit a different Email address!<br />"; 
      unset($email_address); 
   &#125; 
   if($username_check > 0)&#123; 
      echo "The <b>username</b> you have selected has already been registered by another member in our database. Please choose a different Username!<br />"; 
      unset($username); 
   &#125; 
   if($dl_check > 0)&#123; 
      echo "The <b>driver's license</b> you have selected has already been registered by another member in our database. Please choose a different License number or contact our customer support in order to reopen your account.!<br />"; 
      unset($username); 
   &#125; 
   echo "Please go BACK and try again."; // Show the form again! 
   exit();  // exit the script so that we do not create this account! 
&#125;

thanks.

Posted: Thu Jan 22, 2004 7:58 am
by AliasBDI
Works fantastic...I added some more variables to check and it is working exactly how I need it.

Posted: Thu Jan 22, 2004 9:57 am
by microthick
Awesome.

another question

Posted: Fri Jan 23, 2004 3:25 pm
by AliasBDI
what if I wanted to let the field be empty. So it will leave it alone if the field is left blank.

Posted: Fri Jan 23, 2004 3:47 pm
by vigge89

Code: Select all

<?php
if (!empty ($_POST['new_username'])) {
    //update username
}
?>

hmmm

Posted: Fri Jan 23, 2004 4:00 pm
by AliasBDI
vigge89--

Where does this go. I'm not fimiliar with that code..

thanks.

Posted: Fri Jan 23, 2004 4:49 pm
by vigge89
oh, that was just an example, i haven't looked at your code yet...

Posted: Fri Jan 23, 2004 4:51 pm
by vigge89
try placing it between this code:

Code: Select all

<?php
   if($username_check > 0){
      echo "The <b>username</b> you have selected has already been registered by another member in our database. Please choose a different Username!<br />";
      unset($username); 
?>
IE:

Code: Select all

<?php
if (!empty ($_POST['new_username'])) {

   if($username_check > 0){
      echo "The <b>username</b> you have selected has already been registered by another member in our database. Please choose a different Username!<br />";
      unset($username); 

} 
?>

vigge89

Posted: Mon Jan 26, 2004 8:52 am
by AliasBDI
My code has changed a bit since that last time I posted it. The block which we are dealing with here now looks like this:

Code: Select all

$sql_email_check = mysql_query("SELECT email_address FROM users WHERE email_address='$email_address'");
 $sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
 $sql_dl_check = mysql_query("SELECT username FROM users WHERE dl='$dl'");

 $email_check = mysql_num_rows($sql_email_check);
 $username_check = mysql_num_rows($sql_username_check);
 $dl_check = mysql_num_rows($sql_dl_check);

 if(($email_check > 0) || ($username_check > 0) || ($dl_check > 0))&#123;
 	echo "Please fix the following errors: <br />";
 	if($email_check > 0)&#123;
 		echo "<strong>Your <b>email address</b> has already been registered by another member in our database. Please submit a different Email address!<br />";
 		unset($email_address);
 	&#125;
 	if($username_check > 0)&#123;
 		echo "The <b>username</b> you have selected has already been registered by another member in our database. Please choose a different Username!<br />";
 		unset($username);
 	&#125;
 	if($dl_check > 0)&#123;
 		echo "The <b>driver's license</b> you have selected has already been registered by another member in our database. Please choose a different License number or contact our customer support in order to reopen your account.!<br />";
 		unset($username);
 	&#125;
 	echo "Please go BACK and try again."; // Show the form again!
 	exit();  // exit the script so that we do not create this account!
 &#125;
I have more than one checker, so I get a bit confused on how to pull it off without messing up what I have - which I've done already!

Thanks for your help.[/php_man]

viggie89

Posted: Tue Jan 27, 2004 7:24 am
by AliasBDI
I tried this but it did not work. Could my code be wrong?

Code: Select all

if (!empty ($_POST&#1111;'new_username']) || ($_POST&#1111;'new_dl']) &#123;
	if(($username_check > 0) || ($dl_check > 0))&#123;
 		echo "Please fix the following errors: <br />";
 		if($username_check > 0)&#123;
 			echo "The <b>username</b> you have selected has already been registered by another member in our database. Please choose a different Username!<br />";
 			unset($username);
 		&#125;
 		if($dl_check > 0)&#123;
 			echo "The <b>driver's license</b> you have selected has already been registered by another member in our database. Please choose a different License number or contact our customer support in order to reopen your account.!<br />";
 			unset($username);
 		&#125;
 		echo "Please go BACK and try again."; // Show the form again!
 		exit();  // exit the script so that we do not create this account!
 		&#125;
	&#125;

hmmm...

Posted: Wed Jan 28, 2004 3:08 pm
by AliasBDI
Anyone know?