beansandsausages Posted February 27, 2008 Share Posted February 27, 2008 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 More sharing options...
deansatch Posted February 27, 2008 Share Posted February 27, 2008 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 More sharing options...
beansandsausages Posted February 27, 2008 Author Share Posted February 27, 2008 yeah get what you mean using cookies.. Link to comment https://forums.phpfreaks.com/topic/93323-username-check/#findComment-478024 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.