FarrisFahad Posted May 27, 2013 Share Posted May 27, 2013 Hello there members of PHP Freaks, I am having a problem in PHP, I want to make the user like a picture and after he likes it the like button goes away. I tried this, <?php if(!isset($_SESSION["punch_id_" . $fetch["punch_id"]])){<a href="Like.php">Like</a>} ?> and I also have tried, <?php if($_SESSION["punch_id_" . $fetch["punch_id"]] == "punch_id_" . $fetch["punch_id"]){<a href="Like.php">Like</a>} ?> So my question is ... How can I make the like button disappear after the user have clicked it? useing $_SESSION[]. Quote Link to comment https://forums.phpfreaks.com/topic/278447-likes-using-sessions/ Share on other sites More sharing options...
Jessica Posted May 28, 2013 Share Posted May 28, 2013 You'd need to show the code where you set the session variable as well. Quote Link to comment https://forums.phpfreaks.com/topic/278447-likes-using-sessions/#findComment-1432649 Share on other sites More sharing options...
Solution FarrisFahad Posted May 29, 2013 Author Solution Share Posted May 29, 2013 Solved it, I just had to make the $_SESSION["punch_id_" . $fetch["punch_id"]; ] = "punch_id_" . $fetch["punch_id"]; Quote Link to comment https://forums.phpfreaks.com/topic/278447-likes-using-sessions/#findComment-1432840 Share on other sites More sharing options...
ajoo Posted May 29, 2013 Share Posted May 29, 2013 Hi Fahad, I just came across your snippet question and I think I could use a similar solution. Ofcourse I am trying to find a solution to a login issue. Ithink the $fetch command in your php is an ajax implimentation. Can you please quickly explain how this line of code works. Thats all I want to know. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/278447-likes-using-sessions/#findComment-1432916 Share on other sites More sharing options...
Jessica Posted May 29, 2013 Share Posted May 29, 2013 $fetch is a variable, not a "command". There's nothing in this code that indicates AJAX. Please create your own thread, post your code, and describe your problem. Quote Link to comment https://forums.phpfreaks.com/topic/278447-likes-using-sessions/#findComment-1432954 Share on other sites More sharing options...
ajoo Posted May 30, 2013 Share Posted May 30, 2013 Hello Jessica, thanks for the reply. I thought it was ajax cos i thought .$fetch was a command. I am absolutely unfamiliar with ajax but that came into my head and so i wrote that. However i was interested in that line of code because it seems to be checking for session authentication before a button is clicked. That means the code following the if would be executed if ,in this case the session was valid. This was exactly what i was wanting to achieve in a 'user login system" that i am trying to create. I have asked this in another thread started by me named / called " Another login twister". I hope you can help. Thanks loads. Quote Link to comment https://forums.phpfreaks.com/topic/278447-likes-using-sessions/#findComment-1433128 Share on other sites More sharing options...
FarrisFahad Posted May 30, 2013 Author Share Posted May 30, 2013 Hi Fahad, I just came across your snippet question and I think I could use a similar solution. Ofcourse I am trying to find a solution to a login issue. Ithink the $fetch command in your php is an ajax implimentation. Can you please quickly explain how this line of code works. Thats all I want to know. Thanks. Hi, here is how I did it, the below is the like button: <?php if(!isset($_SESSION["punch_id_" . $fetch["punch_id"]])){ ?><a href="Like.php">Like</a><?php }else{ echo NULL; } ?> And here is the like.php file: <?php require_once("connection.php"); $id = $_GET["id"]; mysql_query("UPDATE table SET likes = likes + 1 WHERE id = {$id}"); $_SESSION["punch_id_" . $punch_id] = "punch_id_" . $punch_id; header("Location: ../PicturePunches.php"); exit; ?> I hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/278447-likes-using-sessions/#findComment-1433143 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.