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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.