Hello, I have been learning php stuff for the last few days. Recently, I have learned how to allow user registration, and I have made this simple voting code that allows people to "like" or "upvote" something on my site.

The way the site is set up is there is a list of songs and anyone can upvote songs they like. (The site is at rbnstuff.com) I have not set up user registration on the site, yet, but I know how to do it. (I've done it on another test site I have)

Anyways, I would like help with making it so only users can vote (I think I can figure that out), but make it so they can only vote once (I have no idea how to do this, and I've been Google-searching a lot).

Each song has an id, song title, artist title, and a bunch of other stuff (in a database)
and each user has an id, name, username, and password.

I am really new at this, so I am hoping someone can teach me how to do this rather than just giving me a code (because I probably wouldn't know what to do with it). Any help is greatly, GREATLY appreciated.

6 Years
Discussion Span
Last Post by atalkingfish

You need to set up a votes table:


To find the number of upvotes you just use COUNT in your SELECT sql for a particular song id. You stop a user voting by checking whether or not they exist in the table already for that particular song id.

Edited by diafol: n/a


So is this table going to be separate from the users table and song table that already exist?


int - they will 'relate' to the user_id in the users table and the song_id in the songs table


Okay, I have the table made. For the record, I am doing this on my test site, so instead of "songs", I'll be dealing with "news" (and then when I know how it's all gonna work, I'll be able to figure it out for the songs. So I made the table with news_id and user_id.

EDIT: And I'm doing this partially because I already have a news table with plenty of entries and a few users.

Edited by atalkingfish: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.