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