0

Hi all,
I'm need to devise a server-side method of preventing multiple form submissions. The form is submitted to the same page. I have read about generating a unique value in a session and insert a hidden input field to detect multiple submits, but would this work with a same-page form handler? Here is my code:

<?php
if (isset($_POST['flagged'])) {
          $getflag = mysql_query("SELECT a_flagged FROM auctions WHERE a_id = '$id'");

		if(!$getflag) {		
			die('Flag Query failed: ' . mysql_error());
		}
		else {
			$resultflag = mysql_fetch_assoc($getflag);	
		}

		$addflag = 1;
		$timesflagged = $resultflag['a_flagged'] + $addflag;
	}
		$updateflag = mysql_query("UPDATE auctions SET a_flagged = '$timesflagged' WHERE a_id = '$id'");
?>

<form name="flag" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
	<input type="image" name="flagged" value="flagged" src="/ece60363/images/arrow.gif" 
	height="20px" width="20px" alt="Submit button"> Flag bad auction

Any ideas are welcome.
Thanks,
nonshatter

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by JRM
0

Hi all,
I'm need to devise a server-side method of preventing multiple form submissions. The form is submitted to the same page. I have read about generating a unique value in a session and insert a hidden input field to detect multiple submits, but would this work with a same-page form handler? Here is my code:

<?php
if (isset($_POST['flagged'])) {
          $getflag = mysql_query("SELECT a_flagged FROM auctions WHERE a_id = '$id'");

		if(!$getflag) {		
			die('Flag Query failed: ' . mysql_error());
		}
		else {
			$resultflag = mysql_fetch_assoc($getflag);	
		}

		$addflag = 1;
		$timesflagged = $resultflag['a_flagged'] + $addflag;
	}
		$updateflag = mysql_query("UPDATE auctions SET a_flagged = '$timesflagged' WHERE a_id = '$id'");
?>

<form name="flag" action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
	<input type="image" name="flagged" value="flagged" src="/ece60363/images/arrow.gif" 
	height="20px" width="20px" alt="Submit button"> Flag bad auction

Any ideas are welcome.
Thanks,
nonshatter

It should, since the PHP does not run until after the submit..
Just do the experiment. That's the best to know for sure.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.