masgas Posted November 24, 2006 Share Posted November 24, 2006 Hi!I created a small statistics script in my index, but when I vote my index loads again and if I refresh the page, the same vote is sent to the database... how could I stop this from happening? thank you!!! Quote Link to comment https://forums.phpfreaks.com/topic/28368-adding-to-database/ Share on other sites More sharing options...
marcus Posted November 24, 2006 Share Posted November 24, 2006 Just use a headerOnce you send the vote[code]header("Location: index.php");[/code]Which will redirect it to index and not send any post data Quote Link to comment https://forums.phpfreaks.com/topic/28368-adding-to-database/#findComment-129749 Share on other sites More sharing options...
masgas Posted November 24, 2006 Author Share Posted November 24, 2006 thanks for that one!You see, I have an "if" working that prints a different subject in that <td> once you answered the question... if (!isset($answer)){print question...}else {insertAnswer (); // this is a function that inserts into the DBand then print the results so far from the survey}So if I send it to the index.php the results wont show :( Quote Link to comment https://forums.phpfreaks.com/topic/28368-adding-to-database/#findComment-129773 Share on other sites More sharing options...
marcus Posted November 24, 2006 Share Posted November 24, 2006 Could you show me your whole code? Quote Link to comment https://forums.phpfreaks.com/topic/28368-adding-to-database/#findComment-129774 Share on other sites More sharing options...
masgas Posted November 24, 2006 Author Share Posted November 24, 2006 if (!isset($respondido)){ AconnectDBB (); $sql="SELECT * FROM $tbl_name ORDER BY `id` DESC LIMIT 1 "; $result=mysql_query($sql); //mysql_close ($conQuest); while ($row=mysql_fetch_array($result)){ $Quest = $row["Quest"];}//Here I echo a standard html table with the question itself, a background and plain images...}else { //first insert the value: insAnswer ();//then echo a different table, with the results coming from the DB and a php image://$sqlSi="SELECT * FROM datos WHERE R = 's'";$sqlNo="SELECT * FROM datos WHERE R = 'n'";$sqlNS="SELECT * FROM datos WHERE R = 'ns'";//$sqlNS="SELECT * FROM datos WHERE NS = 'ns'";$sqlT="SELECT * FROM datos";$resultadoSi = mysql_query($sqlSi);$totalSi=mysql_num_rows($resultadoSi);//echo "Sí ".$totalSi."<br>";$resultadoNo = mysql_query($sqlNo);$totalNo=mysql_num_rows($resultadoNo);//echo "No ".$totalNo."<br>";$resultadoNS = mysql_query($sqlNS);$totalNS=mysql_num_rows($resultadoNS);//echo "NS ".$totalNS."<br>";$resultadoT = mysql_query($sqlT);$totalT=mysql_num_rows($resultadoT);//echo "T ".$totalT."<br>";//redondeo Sí$redS = (($totalSi/$totalT))*100;$xS = round($redS);//echo "xS ".$xS."<br>";//redondeo No$redN = (($totalNo/$totalT))*100;$xN = round($redN);//echo "xN ".$xN."<br>";//redondeo NS$redNS = (($totalNS/$totalT))*100;$xNS = round($redNS);//echo "xNS ".$xNS."<br>";mysql_close($con);//$xS =40;$yS =10;//$xN =60;$yN =25;//$xNS =45;$yNS =40;$pic = imagecreate(100, 70);$miAzul = imagecolorallocate($pic,128,149,206);$miAmarillo = imagecolorallocate($pic,255,249,204);$miGris = imagecolorallocate($pic,204,204,204);$miRojo = imagecolorallocate($pic,242,204,204);imagefilledrectangle($pic, 0, 20, $xS, $yS, $miRojo);imagefilledrectangle($pic, 0, 35, $xN, $yN, $miAmarillo);imagefilledrectangle($pic, 0, 50, $xNS, $yNS, $miGris);imageColorTransparent($pic, $miAzul);Imagepng($pic,"pic.png");ImageDestroy($pic);echo "<img src='pic.png'>";} Quote Link to comment https://forums.phpfreaks.com/topic/28368-adding-to-database/#findComment-129783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.