Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8063841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:10:31+00:00 2026-06-05T11:10:31+00:00

I am using a table to store votes of different users on different polls.

  • 0

I am using a table to store votes of different users on different polls.

Table has following structure.

id   |  poll_id  |   opt   |  ip_address

id : auto increment

poll_id : (STRING UNIQUE) unique for a particular poll  

opt : (STRING) option selected by user    

ip_address: (STRING UNIQUE) ip address of user

This is my query

INSERT OR REPLACE INTO tbl_poll(id,poll_id,opt,ip_addr) VALUES (null,'$poll_id','$opt','$ip_addr')

(Here $poll_id, $opt and $ip_addr are php variables which holds the respective values)

Now, the scenario is like this,

User ‘A’ votes for option 2 of poll_id ‘mypoll’. Query works perfectly. (Does insert)

User ‘A’ changes mind and votes for option 5 of poll_id ‘mypoll’. Query works perfectly. (Does replace)

But if User ‘A’ votes for option 4 of poll_id ‘yourpoll’. Query fails (It does a replace) but it should insert a new record with poll_id ‘yourpoll’

I think, it considers the unqiue constraint of ip_address only but not the poll_id

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:10:33+00:00Added an answer on June 5, 2026 at 11:10 am

    From your description on the desired functionality, it would seem that you want poll_id and ip_address to be a unique pair or compound unique.

    CREATE TABLE tbl_poll ( 
        id         INTEGER PRIMARY KEY AUTOINCREMENT,
        poll_id    STRING NOT NULL,
        ip_address STRING NOT NULL,
        opt        STRING NULL,
        CONSTRAINT 'unique_vote_per_poll_per_ip_address' UNIQUE ( poll_id, ip_address )  ON CONFLICT REPLACE 
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using an sqlite database to store log data. My table has a
I'm using a hash table (source code by Google Inc) to store some method
Using MSSQL 2008 and XQUERY Consider the following XML stored in a table: <ROOT>
We have been using temporary table to store intermediate results in pl/sql Stored procedure.
Morning y'all! Basically, I'm using a table to store my main data - called
I will be using the table storage to store a lot of blob names,
I'm using Windows Azure Table Storage to store millions of entities, however I'm trying
I'm just building a table to store hierarchical data using the Modified Pre-order Tree
I'm using a bit(1) field to store boolean values and writing into the table
First of all, let's define a few tables: Users table will store information about

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.