Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Total Votes

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Total Votes

Postby Kenneth » Fri Sep 20, 2002 12:49 pm

Hi everyone:

I just came back to ask this quesiton. It's been a while since I was on here, but over time I made myself a poll. I just wanted to know, on my poll, I use one page to show the form, add the vote, and show the results. My question is, why I vote, and it stays on the same page and shows the results, if I press refresh, it adds the same vote as many times as I press refresh. How can I stop that from happening? Thanks a lot, I really appreciate it!!

Ken Cooper
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY

Postby Jay » Fri Sep 20, 2002 2:50 pm

When you've sent form data, the resulting page is generated using the form data. So if you're refreshing the page, you keep getting the page with the form data being submitted. The problem is every time this happens, your database logs it as an entry.

You've got two options, log according to session ID (once per session) or using their IP address, OR log to another page which transport you back to the results page. So refreshing will redisplay the results page without sending the form data (because that was on a previous page)
Jay
 

Postby Kenneth » Fri Sep 20, 2002 5:24 pm

Yes, on the page where I insert their vote, I also insert their IP with the pollid, so that it will display the votes from now on. Well, I'm hoping to change my poll, but right now, somehow I made it so that when I do do it on 1 page, when you vote on 1 page, click refresh, it shows it once. I was just wondering, does the "mysql_close()" do anything? I put that down, and it didn't insert each refresh. Does that also do it? Thanks!

Ken Cooper
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY

Postby Jay » Sat Sep 21, 2002 3:44 am

mysql_close() closes the connection wherever it occurs within a script. But PHP scripts are not programs. They are accessed and run only when that page is requested. For refreshes or other pages, they are run again!

What you should be doing is using the session ID (since there's a very small chance that will be duplicated) alongside the date and IP (just in case someone closes their browser and comes back to mess up your votes). Then check if the session ID exists, if not, check if that IP posted a vote in the last X minutes, if not, then you can enter the vote!
Jay
 

Postby Kenneth » Sat Sep 21, 2002 5:09 am

Thanks, I will try that. I really appreciate it. But this is the weird thing. If you have time, go to my site: http://www.coopercentral.org and on the homepage, there will be a poll. Just vote on an option. Then right when it shows the results, press refresh, it doesn't add the vote. I KNOW that I'm not using any Session ID's. I am logging IP's so it will show the results, but I don't know. Thanks!

Ken Cooper
Kenneth
New php-forum User
New php-forum User
 
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron