我有以下问题。当我尝试通过 HTML 表单更新用户名值时。这是我的 HTML 表单:
<form action="namechanging.php" method="post">
<br>
<fieldset>
<span class="ico user-ico"></span>
<input name="ingamename" type="text" class="field" value="Example: John_Doe" title="Example: John_Doe" />
</fieldset>
<center><input name="submit" type="submit" class="submit btn blue-btn" value="Change Name" /></center>
</form>
这是我的名称更改.php 文件:
<?php
session_start();
$_SESSION['ingamename'] = $_POST['ingamename'];
$newingamename = $_SESSION['ingamename'];
$nc = $_SESSION['nc'];
if($nc < 1){
$updateresult = '<strong>Error:</strong> You do not have any name changes left. Donate for more...';
header("Location: ucp-home-error.php");
}
else {
$con=mysqli_connect("localhost","USERNAME","PASS","DB-NAME");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$newnc = $nc - 1;
mysqli_query($con,"UPDATE users SET Username=$newingamename WHERE Username='$_SESSION[user]' ");
mysqli_query($con,"UPDATE users SET NameChanges=$newnc
WHERE Username='$_SESSION[user]'");
$updateresult = 'Your In-Game Name was changed successfully. Please re-log!';
header("Location: ucp-home-success.php");
}
mysqli_close($con);
$_SESSION['updateresult'] = $updateresult;?>
它可以从 $nc 中删除 -1,但不会更改用户名。您还应该知道用户名保存在会话中,这就是我登录身份验证页面时使用的用户名。这是我的 auth.php 文件:
<?php
include("sql.php");
session_start();
function Destroy() {
unset($_SESSION['UID']);
unset($_SESSION['USERNAME']);
unset($_SESSION['FULL NAME']);
header("location: account-log-in-restricted.php");
}
if(isset($_SESSION['UID']) && isset($_SESSION['USERNAME'])) {
$UID = $_SESSION['UID'];
$username = $_SESSION['USERNAME'];
$qry = mysql_query("SELECT * FROM `users` WHERE `UID` = '$UID' AND `Username` = '$username'");
if(mysql_num_rows($qry) != 1) { Destroy(); }
} else { Destroy(); }
?>