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条)

报告相同问题?