Php 更新用户';s配置文件页:无法更新数据库中的用户信息
我不知道为什么这不起作用 以下是后端php:Php 更新用户';s配置文件页:无法更新数据库中的用户信息,php,html,mysql,session,Php,Html,Mysql,Session,我不知道为什么这不起作用 以下是后端php: include_once 'dbh-inc.php'; if (isset($_POST['edit'])) { $first = mysqli_real_escape_string( $conn , $_POST['first']); $last = mysqli_real_escape_string( $conn , $_POST['last']); $uid = mysqli_real_escape_string(
include_once 'dbh-inc.php';
if (isset($_POST['edit'])) {
$first = mysqli_real_escape_string( $conn , $_POST['first']);
$last = mysqli_real_escape_string( $conn , $_POST['last']);
$uid = mysqli_real_escape_string( $conn , $_POST['uid']);
$city = mysqli_real_escape_string( $conn , $_POST['city']);
$region = mysqli_real_escape_string( $conn , $_POST['region']);
$country = mysqli_real_escape_string( $conn , $_POST['country']);
$id = $_SESSION['u_id'];
mysqli_query($conn, "UPDATE users SET user_first = '$first', user_last =
'$last', user_uid = '$uid', user_city = '$city', user_region = '$region',
user_country = '$country' WHERE user_id = $id");
}
header("Location: ../my-profile-edit.php");
?>
当我在查询下面放一个:mysqli_error()时,它表示$id未定义,这是我无法理解的,因为该变量在所有其他页面上都可以用于获取当前会话用户id。这是登录页面中代码的证明:
$_SESSION['u_id'] =$row['user_id'];
以下是更新配置文件页面的html代码:
<?php include_once 'Header.php';
$uid = ucfirst($_SESSION['u_uid']);
//THIS CODE ONLY EDITS THE VISIBLE PORTION OF A USERS PROFILE//
?>
<form class="edit-profile" action="includes/edit-profile-inc.php"
method="POST">
<table width="398" border="0" align="center" cellpadding="0">
<tr>
<td width="82" valign="top"><div align="left"> <?php echo $uid ?> </div>
</td>
<td height="26" colspan="2"><input type="text" name="uid"
placeholder="New Username"></td>
<td><div align="right"><a href="index.php">logout</a></div></td>
</tr>
<tr>
<td width="129" rowspan="5"><img src="<?php echo $picture ?>" width="129"
height="129" alt="no image found"/></td>
<td width="82" valign="top"><div align="left">FirstName:</div></td>
<td width="165" valign="top"><input type="text" name="first"
placeholder="New First name"></td>
</tr>
<tr>
<td valign="top"><div align="left">LastName:</div></td>
<td valign="top"><input type="text" name="last" placeholder="New Last
Name"></td>
</tr>
<tr>
<tr>
<td valign="top"><div align="left">City:</div></td>
<td valign="top"><input type="text" name="city" placeholder="New City">
</td>
</tr>
<tr>
<tr>
<td valign="top"><div align="left">Region: </div></td>
<td valign="top"><input type="text" name="region" placeholder="New
Region"></td>
</tr>
<tr>
<td valign="top"><div align="left">Country:</div></td>
<td valign="top"><input type="text" name="country" placeholder="New
Country"></td>
</tr>
<tr>
<td valign="top"><div align="left">About me: </div></td>
<td valign="top">
<input type="text" name="about" placeholder="About me">
</td>
</tr>
<tr>
<td><button type="submit" name="edit">Update profile</button></td>
</tr>
</table>
</form>
<p align="center"><a href="index.php"></a></p>
<?php
include_once 'Footer.php';
?>
“width=“129”
height=“129”alt=“未找到图像”/>
名字:
姓氏:
城市:
地区:
国家:
关于我:
更新配置文件
因此,是的,我对这不起作用的原因有异议,非常感谢您的帮助!很长时间,但请尝试将ID封装在单引号中。例如:
“$ID”
不起作用,不幸的是:(检查您的会话是否已启动。在插入之前,您可能错过了session\u start
。如果会话已启动,请在其中抛出var\u dump($\u session);
以查看可用内容。为了澄清Howard的评论,您尝试在查询中用单引号封装$id,对吗?…其中user\u id='$id'))
mopsyd你是对的,愚蠢的错误,我以为它会被包括在内,因为它在头版。非常感谢大家!