JSHINER Posted April 10, 2007 Share Posted April 10, 2007 I currently have the following: $db->query("INSERT INTO table SET zips = '$zip'"); Whenever someone goes to that page (page.php?zip=00001) it inserts the zip into the database. However, if someone clicks a link on that page, and then hits the back button, the zip is recorded again. Is there a way I could limit it to ONE zip per user? I do not want one entry per user because one user may view multiple zips. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/ Share on other sites More sharing options...
cmgmyr Posted April 10, 2007 Share Posted April 10, 2007 if you have a user id in the table that is associated with the zip before you do the insert you can see if there are any records where the user and the zip are the same as that wants to do the insert. So: 1. Do select statement 2. count rows 3. if($count == 0){ //Insert statement } And you are done. So they can reload the page as much as they want and it will only insert once Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/#findComment-225909 Share on other sites More sharing options...
JSHINER Posted April 10, 2007 Author Share Posted April 10, 2007 I want the zip inserted multiple times - but not by the same user. Would that ID be for the ZIP or for each user that searches that zip? Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/#findComment-225914 Share on other sites More sharing options...
cmgmyr Posted April 10, 2007 Share Posted April 10, 2007 it would be for the user so when user 1 enters zip 13903 and reloads the page 5 times...it only enters it once now user 2 goes and enters 13903...now since it it s different user...it gets inserted Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/#findComment-225920 Share on other sites More sharing options...
per1os Posted April 10, 2007 Share Posted April 10, 2007 You would need a zipid and a userid the zip table would be like this zipid, userid, zipcode Using that logic you can have multiple zips and than to check you would need to run a select query on the userid and see if the new zip is already in the db if it is you do not add it. Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/#findComment-225921 Share on other sites More sharing options...
JSHINER Posted April 10, 2007 Author Share Posted April 10, 2007 How do I get a user ID insterted per user? Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/#findComment-225999 Share on other sites More sharing options...
per1os Posted April 10, 2007 Share Posted April 10, 2007 Create a table users and have each person sign up userid, username, password, email than store that in a cookie or session and when you call that input it with an insert $sql = "INSERT INTO table_name (`userid`, `zipcode`) VALUES ('".$_COOKIE['userid']."', '$zipcode')"; Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/#findComment-226006 Share on other sites More sharing options...
JSHINER Posted April 10, 2007 Author Share Posted April 10, 2007 Oh so each user has to sign up ... is there a way to track via IP - so if IP & ZIP & DATA aleady exist, do not insert. Quote Link to comment https://forums.phpfreaks.com/topic/46445-solved-insert-question/#findComment-226007 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.