How to reformat username


Here is the code:
PHP Code
  1. <?
  2. ob_start()
  3. // Start using cookies
  4. include("config.php");
  5. // Include the config file
  6. if($logged[user])
  7. //checks if user is logged in
  8. {
  9. $olduser = strtolower($logged[user]); //not to sure on how to use the strtolower I forgot but I think thats how you use
  10. // Sets olduser to your old username in lower case
  11. if(!$_POST[changeuser])
  12. //checka if the form hasn't been submited if it hasn't we echo out the table and form
  13. {
  14. Echo("
  15. <table width="224" height="54" border="0" align="center" cellpadding="0" cellspacing="0">
  16. <tr>
  17. <td>Hello here you can re-format your username E.g Hello could be changed to HeLlO </td>
  18. </tr>
  19. <tr>
  20. <td> </td>
  21. </tr>
  22. <tr>
  23. <td>How would you like your username to be formated:<br>
  24. <input name="newname" type="text" size="30" maxlength="15"></td>
  25. </tr>
  26. <tr>
  27. <td> </td>
  28. </tr>
  29. <tr>
  30. <td><input name="changeuser" type="submit" id="1" value="Change format!"></td>
  31. </tr>
  32. </table>");
  33. //Makes a table to be submitted with the users new username format
  34. }
  35. Else{
  36. //if the form has been submit then
  37. $newuser = $_POST[newname];
  38. //set newuser to the username format the user wants
  39. $lowernew = strtolower($newuser);
  40. // sets the wanted username format into lower case so we can tell if it matches with new username format
  41. if(!$lowernew == $olduser)
  42. {
  43. //if the old yourname isnt the same as the new one then echo out the message
  44. Echo("
  45. Sorry thats not the same username as your old username you can only reformat your username not change your username");
  46. //echos out the message saying the username doesnt match to old one
  47. }
  48. else{
  49. // if the username does match to old one then
  50. $updateusername = mysql_query("UPDATE users SET username = '$newuser'
  51. WHERE username='olduser'");
  52. // update the mysql table with the new usernam format
  53. echo("
  54. your username has been change to $newuser");
  55. // if everything was successfull then echo out that its been changed
  56. }
  57. }
  58. else{
  59. //if the user isnt logged in then echo out
  60. echo("Your not logged in please login <a href"urltologin">HERE</a>");
  61. // change urltologin to your url to your login page
  62. ?>

this should work but i haven't tested because i just made it for someone to use on their site :)
thanx hope you enjoy my tutorial
Aidan
(MORE to come!)
Aidan's Avatar
Author:
Views:
2,093
Rating:
There are currently no comments for this tutorial, login or register to leave one.