TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   rate error need help (http://www.talkphp.com/absolute-beginners/1930-rate-error-need-help.html)

webtuto 01-10-2008 06:46 PM

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

webtuto 01-10-2008 07:00 PM

up
up
up...

Alan @ CIT 01-10-2008 07:04 PM

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.

webtuto 01-10-2008 07:07 PM

well ok im gnna do that thanks
i hope there is a way without redirection to another page :s

Alan @ CIT 01-10-2008 07:11 PM

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

Wildhoney 01-11-2008 02:43 AM

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.

webtuto 01-11-2008 01:04 PM

ok thanks ;)


All times are GMT. The time now is 11:26 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0