dongmu1989 2013-04-12 11:48 采纳率: 0%
浏览 23
已采纳

使用$ _POST发送$ _SESSION的问题

I have a function that updates a row in a table, the query works when I hard coded the email value, but when I want to send the value as $_SESSION nothing happens in the row, and I won't get any errors either.

My working query is:

function profile_name($profile_name){
    $profile_name = mysql_real_escape_string(htmlentities($profile_name)); 
    mysql_query("UPDATE user SET user_name = '{$profile_name}' WHERE user_email = 'my@email.com' ");
}

When I send the my@email.com as session with the following code:

(isset($_POST['profile'], $_POST["{$_SESSION['email']}"])){ } 
 function profile_name($profile_name, $email){
    $profile_name = mysql_real_escape_string(htmlentities($profile_name)); 
        mysql_query("UPDATE user SET user_name = '{$profile_name}' WHERE user_email = '{$email}' ");
    }

nothing happens.

If I echo out the session $_SESSION['email'] it prints my@email.com

  • 写回答

2条回答 默认 最新

  • donglv9116 2013-04-12 12:19
    关注

    Still trying to understand what you mean by "sending the $_SESSION", but this statement looks weird:

    $_POST["{$_SESSION['email']}"]
    

    What it does is it's getting a value from $_SESSION array with the key email, and then uses this value as a key to $_POST array.

    Assuming your $_SESSION['email'] is set to myemail@hotmail.com, it would expect $_POST['myemail@hotmail.com'] to return a value. For that your form would have to have an input control with name myemail@hotmail.com.

    Since it is a very irregular way of doing things, I assume it might be a problem, unless it's a typo in your question.

    What you probably meant to do is this:

    if (isset($_POST['profile'], $_SESSION['email'])) {...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导
  • ¥100 数字取证课程 关于FAT文件系统的操作
  • ¥15 如何使用js实现打印时每页设置统一的标题
  • ¥15 安装TIA PortalV15.1报错
  • ¥15 能把水桶搬到饮水机的机械设计
  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器