如何在 PHP 中更新当前用户登录的用户数据库


how to update user database for current user login in php?

我尝试通过这个网站找到答案,但每次尝试,我都得到错误..为什么?我希望登录的用户能够更新自己的信息。但是每次我单击更新时,都没有更新,并在此处显示"错误"我的更新.php页面脚本

 <?php
 include '../config/config.php';
$name = $_POST['name'];
$hobbies = $_POST['hobbies'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$blood_presure = $_POST['blood_presure'];
$heart_rate = $_POST['heart_rate'];

$query = "UPDATE user_info SET name = '$name', hobbies =' $hobbies', height = '$height', weight = '$weight', blood_presure = '$blood_presure' heart_rate = $heart_rate' WHERE   $sessions = '".$_SESSION['user']."'";
  $result = mysql_query($query);
 if($result){
 header("location:../dashboard.php");
 }
else {
echo "ERROR";
} 

mysql_close();
?>

我的错误是什么,我如何为当前登录的用户设置 WHERE 以更新自己的数据是否正确?

更新user_info设置名称 = '$name',爱好 ='

$hobbies',身高 = '$height其中 user_name='';

试试这个添加位置子句并根据您的要求添加任何条件?

关系,我只是设法解决这个问题..这是我的解决方案

    <?php 
   session_start();
    if (!session_is_registered(user))
  {
   header("location:login.php");
}
?>
<?php
include '../config/config.php';

 $name = $_POST['name'];
 $hobbies = $_POST['hobbies'];
 $height = $_POST['height'];
 $weight = $_POST['weight'];
 $blood_presure = $_POST['blood_presure'];
 $heart_rate = $_POST['heart_rate'];
 $sessions = $_SESSION['user'];
  $sql = "UPDATE user_info SET name = '$name', hobbies = '$hobbies', height = '$height', weight = '$weight', blood_presure = '$blood_presure', heart_rate = '$heart_rate' WHERE username = '$sessions'";
  $result= mysql_query($sql);
  if($result){
  header("location:../dashboard.php");
  }
  else {
  echo error_reporting(E_ALL);
  } 

  mysql_close();
  ?>

我需要为会话输入启动会话和变量