Checking User Information
Moderator: General Moderators
Checking User Information
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?
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?
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
Re: Checking User Information
In the form, create a hidden field that contains the username, called originalUsername or something.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?
Then, only run the if statement if $username != $originalUsername.
crap...
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){
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);
}
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);
}
if($dl_check > 0){
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);
}
echo "Please go BACK and try again."; // Show the form again!
exit(); // exit the script so that we do not create this account!
}-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
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) {
$username_check = 0;
} else {
$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){
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);
}
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);
}
if($dl_check > 0){
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);
}
echo "Please go BACK and try again."; // Show the form again!
exit(); // exit the script so that we do not create this account!
}-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
another question
what if I wanted to let the field be empty. So it will leave it alone if the field is left blank.
Code: Select all
<?php
if (!empty ($_POST['new_username'])) {
//update username
}
?>try placing it between this code:
IE:
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);
?>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
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:
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]
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){
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);
}
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);
}
if($dl_check > 0){
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);
}
echo "Please go BACK and try again."; // Show the form again!
exit(); // exit the script so that we do not create this account!
}Thanks for your help.[/php_man]
viggie89
I tried this but it did not work. Could my code be wrong?
Code: Select all
if (!empty ($_POSTї'new_username']) || ($_POSTї'new_dl']) {
if(($username_check > 0) || ($dl_check > 0)){
echo "Please fix the following errors: <br />";
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);
}
if($dl_check > 0){
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);
}
echo "Please go BACK and try again."; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
}