Modifying Username on CMS

Spoderman

y u do dis 2 me
Jun 30, 2013
209
37
I'm currently trying stuff and I need to be able to edit Username on the CMS/account page.
I've tried several different ways but none seem to work, I lack in php knowledge therefore I wouldn't know how to do it via PHP.

If someone could help me out here, it would be great

Cheers lads.
 

Zodiak

recovering crack addict
Nov 18, 2011
453
417
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']."'");
}
}

?>
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

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.
 

Zippy

Member
Aug 5, 2010
92
28
Also be aware that if your CMS uses the username as a salt for the password, the user won't be able to login after changing their username using the above form.
 

Users who are viewing this thread

Top