Jump to content

[SOLVED] INSERT Question


JSHINER

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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')";

Link to comment
Share on other sites

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.