bluegman991 Posted October 4, 2009 Posted October 4, 2009 i have made a couple actions on my preferences page to change email and change login name and i need help also with the change username what i need help with is creating an if statement for each 1 so if a username, login name, or email is already in use you cannot use that username, login, or email. i know some of you pro coders either already have this or know how to do it but if anybody doest know how or need to see the code to get an idea of what the if statement should be tell me and I'll post it Quote
CrazyT Posted October 4, 2009 Posted October 4, 2009 $c_name = sprintf('SELECT userid FROM users WHERE username = "%s" AND userid != %d', $db->escape($_POST['name']), $ir['userid']); $c_name = $db->query($c_name); if ($db->num_rows($c_name) > 0) { echo "Username already taken. "; } There's a starter :) Quote
Danny696 Posted October 4, 2009 Posted October 4, 2009 Not sure if this will work, i just edited the the name change. function login_change() { global $ir,$userid,$h; print "<h3>Login username Change</h3> Please note, this will keep your in-game username the same. just the username you login with will change. <form action='?action=loginchange2' method='post'> New Login Name: <input type='text' name='newname' /> <input type='submit' value='Change!'/></form>"; } function do_login_change() { global $db,$ir,$c,$userid,$h;$r = $db->fetch_row($db->query("SELECT username, loginname FROM users")); if($_POST['newname'] == '$r->username' || $_POST['newname'] == '$r->loginname') { echo'This username is in use.' $h->endpage exit; } if($_POST['newname'] == "") { print "You did not enter a new login name. [url='?action=loginchange']> Back[/url]"; } else { $_POST['newname']=str_replace(array("<", ">", "\\\'"), array("<", ">", "'"), $_POST['newname']); $db->query("UPDATE users SET loginname='{$_POST['newname']}' WHERE userid=$userid"); print "Login name changed!"; } } E-mail change function name_change() { global $ir,$c,$userid,$h; print "<h3>E-Mail Change</h3> <form action='preferences.php?action=emailchange2' method='post'> New Name: <input type='text' name='newemail' /> <input type='submit' value='Change E-Mail!' /></form>"; } function do_login_change() { global $db,$ir,$c,$userid,$h; $r = $db->fetch_row($db->query("SELECT email FROM users")); if($_POST['newemail'] == '$r') { echo'This e-mail is allready in use.' event_add(1, ''.$ir['username'].' attempted to change his/her e-mail to another one that was in use, the e-mail was '.$_POST['newemail'].'. Fedded for 5 days, please look into this.'); $db->query("ALTER TABLE users SET fedjail=5 WHERE userid=$userid"); $db->query("INSERT INTO fedjail VALUES('' $ir['userid'], 5, 'System', 'Multi Email, Look into this')"); $h->endpage exit; } if($_POST['newemail'] == "") { print "You didnt enter a new e-mail, this will break your account! [url='?action=emailchange']> Back[/url]"; } else { $db->query("UPDATE users SET loginname='{$_POST['newname']}' WHERE userid=$userid"); print "Email changed!"; } } Quote
bluegman991 Posted October 4, 2009 Author Posted October 4, 2009 lazy i tried yours but it didn't work and i also tried something similar to it before i posted this thread here is the if statement i tried before posting this thread i simply got it from the register page i tried editing it a whole bunch of different ways but its to many to post :P $q=$db->query("SELECT * FROM users WHERE username='{$username}' OR login_name='{$username}'"); if($db->num_rows($q)) { print "Username already in use. Choose another. >[url='register']Back[/url]"; } and Danny i only need the if statement but what happened with ur if statement is i put it in how it was and then it wouldn't change the username at all it got a query error but i believe the correct thing to refer to is login_name not loginname becuase thats what actually works in the action to change the login name so i put an underscore between login and name but then it continued to change the username whether it was in use or not. heres the query error i got QUERY ERROR: Unknown column 'loginname' in 'field list' Query was SELECT username, loginname FROM users here are my functions that i am currently using name change function name_change() { global $ir,$c,$userid,$h; print "<h3>Name Change</h3> Please note that you still use the same name to login, this procedure simply changes the name that is displayed. <form action='preferences?action=namechange2' method='post'> New Name: <input type='text' name='newname' /> <input type='submit' value='Change Name' /></form>"; } function do_name_change() { global $db,$ir,$c,$userid,$h;$r = $db->fetch_row($db->query("SELECT username FROM users")); if($_POST['newname'] == '$r->username') { die("This username is in use."); $h->endpage(); exit; } if($_POST['newname'] == "") { print "You did not enter a new name. [url='preferences?action=namechange']> Back[/url]"; } else { $_POST['newname']=str_replace(array("<", ">", "\\\'"), array("<", ">", "'"), $_POST['newname']); $db->query("UPDATE users SET username='{$_POST['newname']}' WHERE userid=$userid"); print "Username changed!"; } } login name change function login_change() { global $ir,$c,$userid,$h; print "<h3>Login Name Change</h3><form action='preferences?action=loginchange2' method='post'>New Login Name: <input type='login_name' name='newloginname' value='{$ir['login_name']}' /> <input type='submit' value='Change Login Name' /></form>"; } function do_login_change() { global $db,$ir,$c,$userid,$h; if($_POST['newloginname'] == "") { print "You did not enter a new login name. [url='preferences?action=loginchange']> Back[/url]"; } else { $db->query("UPDATE users SET login_name='{$_POST['newloginname']}' WHERE userid=$userid"); print "Login Name changed!"; } } email change function email_change() { global $ir,$c,$userid,$h; print "<h3>Email Change</h3><form action='preferences?action=emailchange2' method='post'>New Email: <input type='email' name='newemail' value='{$ir['email']}' /> <input type='submit' value='Change Email' /></form>"; } function do_email_change() { global $db,$ir,$c,$userid,$h; if($_POST['newemail'] == "") { print "You did not enter a new email. [url='preferences?action=emailchange']> Back[/url]"; } else { $db->query("UPDATE users SET email='{$_POST['newemail']}' WHERE userid=$userid"); print "Email Address changed!"; } } Quote
CrazyT Posted October 7, 2009 Posted October 7, 2009 $c_name = sprintf('SELECT userid FROM users WHERE UPPER(username) = UPPER("%s") AND userid != %d', $db->escape($_POST['newname']), $ir['userid']); $c_name = $db->query($c_name); if ($db->num_rows($c_name) > 0) { echo "Username already taken. \n"; } $c_login = sprintf('SELECT userid FROM users WHERE UPPER(login_name) = UPPER("%s") AND userid != %d', $db->escape($_POST['new_loginname']), $ir['userid']); $c_login = $db->query($c_login); if ($db->num_rows($c_login) > 0) { echo "Login name already taken. \n"; } There... you can do the rest of it :) Quote
bluegman991 Posted October 7, 2009 Author Posted October 7, 2009 ty lazyt :) i tried it and it said that the name was already in use but still changed it so i added this $h->endpage(); exit; worked great ty again :D wish i knew how to +1 :| Quote
CrazyT Posted October 8, 2009 Posted October 8, 2009 Yup, i only posted that to show you. :) And yeah, you needed to edit it of course :L Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.