jerryhughes70 Posted July 8, 2011 Share Posted July 8, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/241421-inserting-session-name-into-update-query/ Share on other sites More sharing options...
AyKay47 Posted July 8, 2011 Share Posted July 8, 2011 $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 Quote Link to comment https://forums.phpfreaks.com/topic/241421-inserting-session-name-into-update-query/#findComment-1240138 Share on other sites More sharing options...
Pikachu2000 Posted July 8, 2011 Share Posted July 8, 2011 Just assign the value of $_SESSION['name'] to $name. $name = $_SESSION['name']; Quote Link to comment https://forums.phpfreaks.com/topic/241421-inserting-session-name-into-update-query/#findComment-1240139 Share on other sites More sharing options...
jerryhughes70 Posted July 8, 2011 Author Share Posted July 8, 2011 oh... i'm such a goon, i had it all there in front of me then! thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/241421-inserting-session-name-into-update-query/#findComment-1240141 Share on other sites More sharing options...
AyKay47 Posted July 8, 2011 Share Posted July 8, 2011 oh... i'm such a goon, i had it all there in front of me then! thank you very much! just needed that nudge... Quote Link to comment https://forums.phpfreaks.com/topic/241421-inserting-session-name-into-update-query/#findComment-1240149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.