我不知道为什么这不起作用 这是后端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( $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';
?>
所以是的,对于为什么这种方法不起作用,我有些矛盾,非常感谢任何帮助!