PDA

View Full Version : account update error



bberry91
22 Feb 2012, 07:52 PM
i have this code that changes a username, and if it successfully updated, it shows a success message. although when you submit it blank, or if the user already changed their username, and nothing changes in the db, it still shows a success message.


if(isset($_POST['changeUname'])) {
if($newUname != "" && $newUname != null) {
$userID = $_SESSION['testingSiteUserID'];
$query = "SELECT uname, change_uname FROM members WHERE ID='$userID'";
$result = mysql_query($query) or die(mysql_error());

if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result) or die(mysql_error());
if($row['change_uname'] == 0) {
mysql_query("UPDATE members SET uname = '$newUname', change_uname = '1' WHERE ID = '$ID'");
} else {
$changeUnameErrors[] = "You cannot change your username. You have already changed it.";
}
}
} else {
$changeUnameErrors[] = "Please enter a valid username!";
}
if (mysql_affected_rows() > 0) {
$unameChanged = true;
}
}

if($unameChanged == true) {
echo "<p><span style='color:red; font-weight:strong; font-size:12px;'>Your account has been successfully updated!</span><p>";
}