Jump to content

inserting session name into Update Query


jerryhughes70

Recommended Posts

alright chaps....

 

at the moment, if I run this on my page

 

$test = mysql_real_escape_string($_POST['FOOTBALL']);
$name = 'Jerry Hughes';

$sql = "UPDATE upc
SET FOOTBALL='$test'
WHERE Name = '$name'";

$updateresult = mysql_query($sql) or die(mysql_error()); 

echo 'Picks Complete';

 

I get the result of my Select field which is named Football put into the row in my database which is Jerry Hughes.

 

BUT, What I've got is more than one username in the database, about 50 different people in fact, So I want to be able to replace the $name with the name of the person who is logged in.

 

On the page I've got a session running, as they have to log in to get to this page.

 

For instance, when they log in, I run Hi <?=$_SESSION['name']?>  which says Hi Jerry Hughes as the name I've logged in with is Jerry Hughes.

 

How do I go incorporating this into my UPDATE query above, so it takes the name of who's logged in and inserts the FOOTBALL thing into their row in the database?

 

Any help makes me a very happy chappy!

$test = mysql_real_escape_string($_POST['FOOTBALL']);
$name = $_SESSION['name'];

$sql = "UPDATE upc
SET FOOTBALL='$test'
WHERE Name = '$name'";

$updateresult = mysql_query($sql) or die(mysql_error()); 

echo 'Picks Complete';

 

note that you will need to declare session_start at the beginning of your script

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.