NSW42 Posted March 29, 2007 Share Posted March 29, 2007 Heya all, what im trying to do and without success is to get my nickname change script to detect the nickname is available or taken, it updates the nick fine but i need it to say nick in use try again, ive tried playing around with it but im still very new to all this, my coding posted below and any help is appreciated, thanks... <? include("config.php"); include("user_check.php"); print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red></a></center><BR><BR>"); $sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'"); $row = mysql_fetch_array($sql); if($action==update) { $update4 = mysql_query("UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'"); print("Your information is now updated."); } { print(" <table> <tr><td align=center><font color=ffffcc><b>Nickname Information</b></td></tr> <form action=$PHP_SELF?action=update method=post> <tr> <td><font color=red>Current NickName</td> <td><input type=text name=nickname value='$row[nickname]' size=25 maxlength=60></td> </tr> <tr> </td> </tr> <tr> </tr> <tr> <tr><td align=center><input type=submit value='Click To Update'></td></tr> </form> </table> this is the $sqlcheckn that works fine for new signups that ive been trying to add into the above script with no luck.. $sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'"); $checkn = mysql_num_rows($sqlcheckn); if((!$nickname) || ($checkn > 0)) if($checkn > 0) { print("Nickname already in use!<BR>"); unset($nickname); } Quote Link to comment Share on other sites More sharing options...
btherl Posted March 29, 2007 Share Posted March 29, 2007 Instead of $update4 = mysql_query("UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'"); use $sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'"; $update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error()); Make that change to each mysql_query() call. Otherwise you will not be notified of errors. Quote Link to comment Share on other sites More sharing options...
NSW42 Posted March 29, 2007 Author Share Posted March 29, 2007 it updates the nickname without a hiccup now, but if someone puts in the same nick it adds it to the db, thats where i need the sqlcheck so it can say no nickname taken or if its not, then just update it, sorry if I may have gotten your reply wrong as im still very new to this and trying very hard to learn it as i go along... Quote Link to comment Share on other sites More sharing options...
NSW42 Posted March 30, 2007 Author Share Posted March 30, 2007 ok i kinda worked out what you were saying and added in this below, it now detects if nickname is taken, but it wont halt and inserts the nickname, half way there i guess, anymore ideas so i can finsih it off would be good thanks... <? include("config.php"); include("user_check.php"); print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red></a></center><BR><BR>"); $sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'"); $row = mysql_fetch_array($sql) or die("Mysql error in $sql\nError: " . mysql_error()); $sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'"); $checkn = mysql_num_rows($sqlcheckn); if((!$nickname) || ($checkn > 0)) if($checkn > 0) { print("Nickname already in use!<BR>"); unset($nickname); } if($action==update) { $sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'"; $update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error()); print("Your information is now updated."); } { print(" <table> <tr><td align=center><font color=ffffcc><b>Nickname Information</b></td></tr> Quote Link to comment Share on other sites More sharing options...
Waldir Posted March 30, 2007 Share Posted March 30, 2007 <? include("config.php"); include("user_check.php"); print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red>[/url]</center><BR><BR>"); $sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'"); $row = mysql_fetch_array($sql) or die("Mysql error in $sql\nError: " . mysql_error()); $sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'"); if($action==update) { if(mysql_num_rows($sqlcheckn) > 0) { print("Nickname already in use!<BR>"); unset($nickname); } else { $sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'"; $update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error()); print("Your information is now updated."); } } ?> Quote Link to comment Share on other sites More sharing options...
NSW42 Posted March 30, 2007 Author Share Posted March 30, 2007 i tried that and got errors everywhere :-\ heres the complets script if u could look at it and see whats going on, sorry to be a pain and thanks agian.. <H3>Edit Your Nickname</H3> <td width='240'> <? include("config.php"); include("user_check.php"); print("<left><a href='$PHP_SELF?action=pass'><a href='$PHP_SELF?action=profile'><font color=red></a></center><BR><BR>"); $sql = mysql_query("SELECT * FROM users WHERE username = '$_COOKIE[username]'"); $row = mysql_fetch_array($sql) or die("Mysql error in $sql\nError: " . mysql_error()); $sqlcheckn = mysql_query("SELECT * FROM users WHERE nickname = '$_POST[nickname]'"); $checkn = mysql_num_rows($sqlcheckn); if((!$nickname) || ($checkn > 0)) if($checkn > 0) { print("Nickname already in use!<BR>"); unset($nickname); } if($action==update) { $sql = "UPDATE users SET nickname = '$_POST[nickname]' WHERE username = '$_COOKIE[username]'"; $update4 = mysql_query($sql) or die("Mysql error in $sql\nError: " . mysql_error()); print("Your information is now updated."); } { print(" <table> <tr><td align=center><font color=ffffcc><b>Nickname Information</b></td></tr> <form action=$PHP_SELF?action=update method=post> <tr> <td><font color=red>Current NickName</td> <td><input type=text name=nickname value='$row[nickname]' size=25 maxlength=60></td> </tr> <tr> </td> </tr> <tr> </tr> <tr> <tr><td align=center><input type=submit value='Click To Update'></td></tr> </form> </table> "); } { include("$sitepath/html/footer.php"); exit; } include("$sitepath/html/footer.php"); ?> Quote Link to comment Share on other sites More sharing options...
NSW42 Posted March 30, 2007 Author Share Posted March 30, 2007 ok thanks very much for all your help, I have managed to fix it, once again thank you. Quote Link to comment Share on other sites More sharing options...
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.