更新用户配置文件页面:无法更新数据库中的用户信息

yptwkmov  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(250)

我不知道为什么这不工作这里是后端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';
     ?>

所以,是的,我不同意为什么这是不工作,任何帮助将不胜感激!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题