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

时间:2014-12-27 07:26:58

标签: php

我尝试通过这个网站找到答案,但每次尝试我都做,我有错误..为什么? 我希望用户登录,启用更新自己的信息。但每次我点击更新,没有任何更新,并继续显示"错误"这里是我的update.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是正确的?

2 个答案:

答案 0 :(得分:0)

UPDATE user_info SET name ='$ name',hobbies ='$ hobbies',height ='$ height where user_name ='';

尝试添加where子句并根据您的要求添加任何条件?

答案 1 :(得分:0)

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

    <?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();
  ?>

我需要为会话

添加启动会话和变量