graham23s Posted June 5, 2007 Share Posted June 5, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/54333-solved-stop-mysql-insert-duplicate-entry/ Share on other sites More sharing options...
per1os Posted June 5, 2007 Share Posted June 5, 2007 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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54333-solved-stop-mysql-insert-duplicate-entry/#findComment-268700 Share on other sites More sharing options...
graham23s Posted June 5, 2007 Author Share Posted June 5, 2007 damn i never thought of that thanks frost:) Graham Quote Link to comment https://forums.phpfreaks.com/topic/54333-solved-stop-mysql-insert-duplicate-entry/#findComment-268704 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.