Jump to content

Form is submitting on page load instead of when 'submit' button pressed


simcoweb

Recommended Posts

This is bugging the hell out of me. This page contains a form that is supposed to insert input based to the MySQL database after it's inserted and the submit button is pressed. Instead it's submitting blank data upon page load. I can't see where it's doing this. I need some new sets of eyes to look this over.

 

Here's the PHP code which validates if there's a valid record for that date. If not, then it allows the user to post the data. What I get instead is all fields blank except the id which is auto-incremented and the date which is set in the variables and posted automatically. I need to stop this form from submitting upon page load.

 

<?
				$v_sbm=$_REQUEST['submit'];  
				$connection = mysql_connect($dbhost, $dbusername, $dbpass);
				$SelectedDB = mysql_select_db($dbname);
			// set our POST variables
			$step1 = mysql_real_escape_string($_POST['step1']);
			$step2 = mysql_real_escape_string($_POST['step2']);
			$step3 = mysql_real_escape_string($_POST['step3']);
			$step4 = mysql_real_escape_string($_POST['step4']);
			$details = mysql_real_escape_string($_POST['details']);
			$opentrades = mysql_real_escape_string($_POST['opentrades']);
			$date  = date("m/d/Y");
			$err   = "";

				// validate data
/*				
			  if(trim($step1)== "") {
			  $err .="Step One cannot be blank.<br>";
			  }    
			  if(trim($step2)== "") {
			  $err .="Step Two cannot be blank.<br>";
			  }
			  if(trim($step3) == "") {
			  $err .="Step Three cannot be blank.<br>";
			  }
			  if(trim($step4) == "") {
			  $err .="Step Four cannot be blank.<br>";
			  }  
			 if (!$err) { */
			 // check to see if today's date already exists in picks'
			 $check = "SELECT * FROM picks WHERE date='$date'";
			 $results = mysql_query($check) or die(mysql_error());
			 $num_rows = (mysql_num_rows($results));
			 if ($num_rows >= 1) {
			   echo "There is already a pick for this date. You can not add another but you can edit
			   the pick by choosing Edit Today's Picks in the menu on the left.<br/>\n";
			   exit();
			} else {

			   $sql = "INSERT INTO picks (step1, step2, step3, step4, details, opentrades, 
			    date) VALUES ('$step1', '$step2', '$step3', '$step4', 
			   '$details', '$opentrades', '$date')";
			   $results = mysql_query($sql) or die(mysql_error());
			   if(!results ) {
			     echo "Could not enter new picks into database. Please re-enter.<br>\n";
				} else {
				  if (isset($_POST['submit'])) {
				 echo "New picks successfully entered for $date.<br>\n";

				   echo "<ul><li>Step 1: $step1</li>\n
				             <li>Step 2: $step2</li>\n
							 <li>Step 3: $step3</li>\n
							 <li>Step 4: $step4</li>\n
							 <li>Details: $details</li>\n
							 <li>Open Trades: $opentrades</li>\n
							 </ul><br>\n";
				}
		}
			}
				//}

?>

 

Just a note, the form field validation was commented out on purpose. The client didn't want the fields required.

Link to comment
Share on other sites

This is the only javascript on the page:

 

<script language="javascript">

function open_window() {

OpenWin = this.open("help.htm#planaccess", 'instruction','toolbar=no,scrollbars=no,location=no,directies=no,status=no,menu=no,width=550,height=450');

}

</script>

Link to comment
Share on other sites

I suggest you try to open file without JS ...

Or try to disable JS in your browser...

This will give you chance to locate the source of problem.

And when you are modifying your script and refresh in browser always remember to delete cache.

It would be much easier to bother with your problem if you give URL address...

 

You can PM me...

 

Best regards..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.