I am developing a fun script where user will be guessing images by putting points for each image which the game owner will be displaying. If he guesses right, his points will be doubled. If he fails to guess, the points will be added to game owner.
In this, After submitting the form, the images which user has guessed and the images game owner displays, will be shown in the page. After that the calculations will happen.
I have properly done all the steps, but if the user reloads the page from browser refresh button, the calculations happens again and again . Not getting how to avoid this.
I can not use
header("location: reditect_page.php");
exit();
As the user should see the data.
Can somebody suggest me to resolve this?
Here is the my submission page
if(isset($_POST['guess']))
{
//user entered/guessed images
$img1 = $_POST['img1'];
$img2 = $_POST['img2'];
$img3 = $_POST['img3'];
$img1_pnt = $_POST['point1'];
$img2_pnt = $_POST['point2'];
$img3_pnt = $_POST['point3'];
$sn1 = mysqli_query($con, "SELECT * from images where id=".$img1."");
$sn2 = mysqli_fetch_array($sn1);
$mn1 = mysqli_query($con, "SELECT * from images where id=".$img2."");
$mn2 = mysqli_fetch_array($mn1);
$is1 = mysqli_query($con, "SELECT * from images where id=".$img2."");
$is2 = mysqli_fetch_array($is1);
//game Owner's image
$k1 = "SELECT * FROM days_data WHERE id=".$gid." AND lead=".$_SESSION['lead']." ORDER BY id DESC LIMIT 1";
$k2 = mysqli_query($con, $k1);
$k3 = mysqli_fetch_array($k2);
$var1 = $k3['img1'];
$var2 = $k3['img2'];
$var3 = $k3['img3'];
$vararray = array($var1, $var2, $var3);
$s1 = mysqli_query($con, "select * from images where id = ".$var1."");
$s2 = mysqli_query($con, "select * from images where id = ".$var2."");
$s3 = mysqli_query($con, "select * from images where id = ".$var3."");
$q1 = mysqli_fetch_array($s1);
$q2 = mysqli_fetch_array($s2);
$q3 = mysqli_fetch_array($s3);
//Display User guessed images
echo '<div class="row gutter30" style="margin-top:20px;">
<h2>Guessed Data</h2>
<div class="col-xs-4">
<img src="img/'.$mn2['image'].'" class="image" />
</div>
<div class="col-xs-4">
<img src="img/'.$sn2['image'].'" class="image" />
</div>
<div class="col-xs-4">
<img src="img/'.$is2['image'].'" class="image" />
</div>
</div>
//Game Owner's Images
<div class="row gutter30" style="margin-top:20px;">
<h2>RESULT</h2>
<div class="col-xs-4">
<img src="img/'.$q1['image'].'" class="image" />
</div>
<div class="col-xs-4">
<img src="img/'.$q2['image'].'" class="image" />
</div>
<div class="col-xs-4">
<img src="img/'.$q3['image'].'" class="image" />
</div>
//Here i will do the calculations of points
if(($_POST['img1_pnt'])!='')
{
if(in_array($_POST['img1'], $vararray))
{
// Calculations part
}
}
}