Jaynesh Posted July 9, 2011 Share Posted July 9, 2011 Hello This is the layout of my table post_id up 1 5 I have set up a link. Whenever somebody clicks the link it executes this query. Basically it increments the up column by 1. How do I limit somebody from clicking it just once? UPDATE Posts SET up = up +1 WHERE $up = post_id Quote Link to comment https://forums.phpfreaks.com/topic/241500-disable-after-update/ Share on other sites More sharing options...
freelance84 Posted July 9, 2011 Share Posted July 9, 2011 You would have to store somewhere that the user hand done so. If they are a member, then in a table. If not then in a cookie. Quote Link to comment https://forums.phpfreaks.com/topic/241500-disable-after-update/#findComment-1240530 Share on other sites More sharing options...
Andy11548 Posted July 9, 2011 Share Posted July 9, 2011 This probably isn't the best way, but it should work. In the `users` table in your database, add a new field saying something like "clicked", then make it so that if they clicked the link it would update the users table such as: $clicked = mysql_query("UPDATE `users` SET `clicked`='Y' WHERE `username`='$_SESSION[username]'"); then you could perform a check to check if its been clicked using something like $clickCheck = mysql_query("SELECT `clicked` FROM `users` WHERE `username`='$_SESSION[username]'"); $clickF = mysql_fetch_assoc($clickCheck); if($clickF['clicked']=='Y') { echo 'You have already clicked the link'; header('REFRESH: 5; index.php'); } Sorry if the code is bad, I'm still a newbie at this, but just adapt that code to how you want it, and it should work. Quote Link to comment https://forums.phpfreaks.com/topic/241500-disable-after-update/#findComment-1240531 Share on other sites More sharing options...
freelance84 Posted July 9, 2011 Share Posted July 9, 2011 Or you could set up a new table: ID clickedID When the user clicks the link which increments the field in the OP, it first checks to see if the users ID is in the above table, if it is send back a message saying, 'sorry you voted already, if no record is in the above table, then increment the link then add the users ID and the clickedID into the above table. That way you can add as many clicked records as you like. Quote Link to comment https://forums.phpfreaks.com/topic/241500-disable-after-update/#findComment-1240534 Share on other sites More sharing options...
Jaynesh Posted July 9, 2011 Author Share Posted July 9, 2011 Hello freelance84, I've created a new table. (user_id, post_id, clicked) I know have a query whenever somebody clicks the link it adds a "1" to the clicked column. Now how do I disable the link if it is set to "1"? Quote Link to comment https://forums.phpfreaks.com/topic/241500-disable-after-update/#findComment-1240538 Share on other sites More sharing options...
freelance84 Posted July 9, 2011 Share Posted July 9, 2011 I think i misunderstood your OP... Is this some kind of voting system, and you only want the users to vote on any one thing once? Quote Link to comment https://forums.phpfreaks.com/topic/241500-disable-after-update/#findComment-1240544 Share on other sites More sharing options...
Andy11548 Posted July 9, 2011 Share Posted July 9, 2011 Jaynesh Why don't you make the link visiable if they haven't clicked it, but once they have, the link is gone? Quote Link to comment https://forums.phpfreaks.com/topic/241500-disable-after-update/#findComment-1240547 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.