Byte Forums
»
Computing
»
Programming
»
Web Programming
How can I create a simple poll with PHP?
|
|
|
How can I create a simple poll with PHP?
|
|
11-16-2007, 03:51 AM
Post: #1
|
|||
|
|||
|
How can I create a simple poll with PHP?
Let's say I wanted to have a poll, and store that information into mySQL from PHP, how would I go about this?
|
|||
|
11-16-2007, 08:08 AM
(This post was last modified: 11-16-2007 08:09 AM by goughy000.)
Post: #2
|
|||
|
|||
|
RE: How can I create a simple poll with PHP?
well firstly you need to think of a table structure that would work.
something like id | ip | voted_for | timestamp and with example data: id | ip | voted_for | timestamp 1 | 127.0.0.1 | 1 | 1049273812 2 | 192.168.1.1 | 2 | 1049275982 3 | 82.37.87.87 | 1 | 1049276499 then you can insert data using php inserts like in the other tutorial. first thing you need to do is make your poll and it's html form then post its code and i'll assist you further. ![]() Web Hosting | Shoutcast Servers | Custom Solutions |
|||
|
11-16-2007, 09:55 PM
Post: #3
|
|||
|
|||
|
RE: How can I create a simple poll with PHP?
Table structure... like as stated above....
Setup the actual poll html form... posts to itself or another page, check if post data submitted and verify it is clean input, then do an sql insert to your table. The poll form should also check and see if they have already voted before it displays them the actual vote options, else have a way to throw an error message if they try again, but if you do a check prior to displaying it, you can display the results instead. as for results, I'm too lazy. But also, you may want another section of your table for specifying which poll they voted in. This would become necessary for archiving or holding multiple polls, unless you do some php to check timestamps compared to the opening of polls and separate from there. most of this probably made no sense. great. |
|||
|
11-17-2007, 01:51 AM
(This post was last modified: 11-17-2007 01:54 AM by darkfate.)
Post: #4
|
|||
|
|||
|
RE: How can I create a simple poll with PHP?
I created this in about 15 minutes and it's not yet complete: http://darkfate.zoomcities.ws/poll.phps
It basically serializes the answers and votes into separate columns. It then unserializes back into an array for output. I haven't put any functions in yet for making a poll though. If you want to, you have to serialize an array of answers and one with the answers and votes. With this system, you can have as many options as you want in the poll. The TEXT field type allows for 65535 (because 2^16 - 1) characters so I don't think you'll be running out anytime soon. I'll do the admin all tomorrow since I have work to do for tomorrow and I watch Numb3rs at 10PM. The key to life is sincerity. Once you can fake that, you’ve got it made. - Groucho Marx |
|||
|
« Next Oldest | Next Newest »
|
| Possibly Related Threads... | |||||
| Thread: | Author | Replies: | Views: | Last Post | |
| [Tutorial] Simple one page website | goughy000 | 13 | 1,121 |
08-15-2007 02:28 PM Last Post: Birdie |
|










