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
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'])) {...
I think both columns are not integers, SO the values should be wrap with single quotes,
UPDATE user SET user_name = '{$profile_name}' WHERE user_email = '{$email}'
I'll suggest that you switch on using PDO
or MySQLi
.