Reply to thread

Edit username? you mean edit your own username or a staff editing someone elses username?

If your referring to a user changing there name via account settings:

Top of the page add:

[PHP]<?php


$username = mysql_real_escape_string($_POST['username']);


if($_POST['update']) {

$checkuser = mysql_query("SELECT * FROM `users` WHERE `username` = '".$username."'");


if(mysql_num_rows($checkuser) == 1)

{

$error = "Username taken";

}

else

{

mysql_query("UPDATE `users` SET `username` = ".$username."'' WHERE `username` = '".$_SESSION['user']['username']."'");

}

}


?>[/PHP]

And the form:

[HTML]<form method="post">

<input type="text" name="username" placeholder="username" value="<?php echo $_SESSION['user']['username']; ?>">

<input type="submit" name="update" value="Update Account">

</form[/HTML]


Not the most effecient way to code it but it should work, unless I've made a mistake which I may have considering I'm half asleep and rushed on it.

Note: This won't work if your php is updated, as mysql was deprecated.


Top