Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/241500-disable-after-update/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.