Jump to content

Recommended Posts

Hi Guys,

 

to keep track of who has dfownloaded files on my site i have a table

 

downloads

 

within this table is 3 rows

 

id  :  file_id  :  downloaders_id

 

all are (int) my question is if the same user downloads the file again another entry is made for them (the auto increment id is different) but i didn't want the same user to have more than 1 file_id and downloaders_id the same

 

i know i can query mysql to see if the details are the same but if i find the entry has already been added wheat's the best way to stop that entry going in.

 

thanks for nay help

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/54333-solved-stop-mysql-insert-duplicate-entry/
Share on other sites

The best way to stop the entry from going in is not running the sql IE:

 

<?php

$sql = "SELECT id FROM downloads WHERE file_id = '" . $file_id . "' and downloaders_id = '" . $downloaders_id . "' LIMIT 1";
$qu = mysql_query($sql);

if (mysql_num_rows($qu) < 1) {
     $sql = "INSERT INTO downloads ....";
     mysql_query($sql);
}

?>

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.