Jump to content

Username check.


beansandsausages

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
https://forums.phpfreaks.com/topic/93323-username-check/
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
https://forums.phpfreaks.com/topic/93323-username-check/#findComment-478018
Share on other sites

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.