TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-10-2008, 06:46 PM   #1 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default rate error need help

hi

i use this code but everytime the user refresh the page its like if he rate again :s

PHP Code:
<form method="post" action="">
<b>Rate this tutorial</b> <select name="rate">
<option name='ra' selected>Rate</option>
<option name=1>1</option>
<option name=2>2</option>
<option name=3>3</option>
<option name=4>4</option>
<option name=5>5</option>
<input type="submit" value="rate" name="value">
</form>
<?php
if($_POST['value']){
$sql="INSERT INTO rate set rate='$_POST[rate]',tuto_id='$get'";
$res mysql_query($sql) or die('Database error: ' mysql_error());
if(
$res) {
  echo
"Thanks for rating<br><br>";
}else{echo
"it was a problem in the rate plz try again!<br><br>";}
}
if(!isset(
$_POST['ra'])){
$web="SELECT SUM(`rate`) / COUNT(`rate`) as rate from `rate`";
$tuto=mysql_query($web) or die('Database error: ' mysql_error());
$mas=mysql_fetch_array($tuto);
echo
"The Rating of this tutorial is : <font color=red>".$mas['rate']."</a><br><br>";
}
whats solution
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-10-2008, 07:00 PM   #2 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

up
up
up...
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-10-2008, 07:04 PM   #3 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

This is a common problem when submitted forms using POST. If you refresh the page your web browser will re-post the form to the script.

A common way to overcome this is to redirect the user to another page once the form has been submitted so that they are unable to re-post the form (well, without going back to the previous page).

Alan.
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
The Following User Says Thank You to Alan @ CIT For This Useful Post:
webtuto (01-10-2008)
Old 01-10-2008, 07:07 PM   #4 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

well ok im gnna do that thanks
i hope there is a way without redirection to another page :s
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Old 01-10-2008, 07:11 PM   #5 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

There are a few other solutions out there - take a look at some of these sites for more ideas: PHP post refresh - Google Search

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 01-11-2008, 02:43 AM   #6 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I think I understand you. The best way is to forward the user back to another page using the header function. Therefore if they tried to refresh, they POST data has gone and so it will not be re-posted.

php Code:
header('location: anotherPage.php') /* FQDN, ideally */
exit; /* Always exit */

For this reason: why you should exit after header.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
webtuto (01-11-2008)
Old 01-11-2008, 01:04 PM   #7 (permalink)
The Addict
 
webtuto's Avatar
 
Join Date: Dec 2007
Location: morocco
Posts: 221
Thanks: 19
webtuto is on a distinguished road
Default

ok thanks ;)
__________________
Send a message via MSN to webtuto Send a message via Yahoo to webtuto Send a message via Skype™ to webtuto
webtuto is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:43 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design