Jump to content

Username check.


burnside

Recommended Posts

Hey i have a VERY simple script to check if a username all ready taken :

 if($_GET['action'] == "personel" )
			{

			$username = $_POST['username'];
			$check1 = mysql_query("SELECT username FROM members WHERE username='$username'");

	 if ((mysql_num_rows($check1) != 0)) {
			echo 'Sorry, Name already in use<br>';
			 }
 else {
 $updateuserdb = mysql_query("update members set username='$username'  where id=$info[id]");
echo "You have changed your username. You need to relogin please.<br>";
 }
}

it works fine, Problem is i want to add a few more details like email address etc .... all i want to know is there away if they dont change there username it wont display the name all ready taken error.?

 

Sorry if i havent explaned this very well.

Link to comment
Share on other sites

If it is for updating account or profile info, I would assume the user would be logged in already so you would have a username stored in a session.

 

If you make an if statement like

if($_GET['action'] == "personel" )
			{
			$username = $_POST['username'];
$email = $_POST['email'];
if($_SESSION['username'] != $username ){
$check1 = mysql_query("SELECT username FROM members WHERE username='$username'");

	 if ((mysql_num_rows($check1) != 0)) {
			echo 'Sorry, Name already in use<br>';
			 }
 else {
 $updateuserdb = mysql_query("update members set username='$username'  where id=$info[id]");
echo "You have changed your username. You need to relogin please.<br>";
 }
}

 elseif($_SESSION['username'] == $username ) {
 $updateuserdb = mysql_query("update members set email='$email' where id=$info[id]");
echo "You have changed your email.";
 }
}

 

Something like that anyway.

Link to comment
Share on other sites

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.