Jump to content

My form is submitting on page load, help!


theredking

Recommended Posts

Hello all, I'm very new to this... A friend has helped me get this far, but as he is currently unavailable I've been trying to trouble shoot for myself. I have a simple form that sends information to a MYSQL database, with the intention of it populating an html table elsewhere. This it does. The problem is that the form submits upon page load, before any data is input, and before the submit button has been clicked. How do I stop this? I know I could put some required fields coding in there, and I will in time, but I don't want a user to see this when they first hit the page. I've tried reading the POST REDIRECT GET tutorials, but I just don't understand how to implement that. I don't want to prevent multiple submissions, but I do want to prevent duplicate submissions. Right now, a page reload will resend the information.

 

Thank you in anticipation... here's the page

 

<html>
<head>
<title>Test</title>
</head>

<body>

<?php
require ('connect.php');

if (isset($_POST)) {

$var1 = $_POST['company'];
$var2 = $_POST['city'];
$var3 = $_POST['state'];
$var4 = $_POST['friam'];
$var5 = $_POST['fripm'];
$var6 = $_POST['satam'];
$var7 = $_POST['satpm'];
$var8 = $_POST['sunam'];
$var9 = $_POST['sunpm'];
$var10 = $_POST['monam'];
$var11 = $_POST['monpm'];
$var12 = $_POST['ti'];
$var13 = $_POST['tr'];
$var14 = $_POST['we'];
$var15 = $_POST['emc'];
$var16 = $_POST['website'];
$var17 = $_POST['email'];

$query="INSERT INTO `registeredcompanies` (`company`,`city`,`state`,`friam`,`fripm`,`satam`,`satpm`,`sunam`,`sunpm`,`monam`,`monpm`,`ti`,`tr`,`we`,`emc`,`website`,`email`) VALUES ('$var1','$var2','$var3','$var4','$var5','$var6','$var7','$var8','$var9','$var10','$var11','$var12','$var13','$var14','$var15','$var16','$var17')";

$result = mysql_query ( $query );

if (empty($result)) { 
$output .="Error";
} else {
$output .="Database Updated";	

mysql_close();	

  }

  echo $output . "<br><br>";

}

?>
	<form name="registeredcompanies" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
		Company:<input type="text" name="company" size="24"> City:<input type="text" name="city" size="24"> State:<select name="state" size="1">
				<option>-Select-</option>
				<option value="AL">Alabama</option>
				<option value="AK">Alaska</option>
				<option value="AZ">Arizona</option>
				<option value="AR">Arkansas</option>
				<option value="CA">California</option>
				<option value="CO">Colorado</option>
				<option value="CT">Connecticut</option>
				<option value="DE">Delaware</option>
				<option value="FL">Florida</option>
				<option value="GA">Georgia</option>
				<option value="HI">Hawaii</option>
				<option value="ID">Idaho</option>
				<option value="IL">Illinois</option>
				<option value="IN">Indiana</option>
				<option value="IA">Iowa</option>
				<option value="KS">Kansas</option>
				<option value="KY">Kentucky</option>
				<option value="LA">Louisiana</option>
				<option value="ME">Maine</option>
				<option value="MD">Maryland</option>
				<option value="MA">Massachusetts</option>
				<option value="MI">Michigan</option>
				<option value="MN">Minnesota</option>
				<option value="MS">Mississippi</option>
				<option value="MO">Missouri</option>
				<option value="MT">Montana</option>
				<option value="NE">Nebraska</option>
				<option value="NV">Nevada</option>
				<option value="NH">New Hampshire</option>
				<option value="NJ">New Jersey</option>
				<option value="NM">New Mexico</option>
				<option value="NY">New York</option>
				<option value="NC">North Carolina</option>
				<option value="ND">North Dakota</option>
				<option value="OH">Ohio</option>
				<option value="OK">Oklahoma</option>
				<option value="OR">Oregon</option>
				<option value="PA">Pennsylvania</option>
				<option value="RI">Rhode Island</option>
				<option value="SC">South Carolina</option>
				<option value="SD">South Dakota</option>
				<option value="TN">Tennessee</option>
				<option value="TX">Texas</option>
				<option value="UT">Utah</option>
				<option value="VT">Vermont</option>
				<option value="VA">Virginia</option>
				<option value="WA">Washington</option>
				<option value="DC">Washington, DC</option>
				<option value="WV">West Virginia</option>
				<option value="WI">Wisconsin</option>
				<option value="WY">Wyoming</option>
				<option value="Non-US">Outside US</option>
			</select>
		<p>Friday AM:<input type="checkbox" name="friam" value="x"> PM:<input type="checkbox" name="fripm" value="x"></p>
		<p>Saturday AM:<input type="checkbox" name="satam" value="x"> PM:<input type="checkbox" name="satpm" value="x"></p>
		<p>Sunday AM:<input type="checkbox" name="sunam" value="x"> PM:<input type="checkbox" name="sunpm" value="x"></p>
		<p>Monday AM:<input type="checkbox" name="monam" value="x"> PM:<input type="checkbox" name="monpm" value="x"></p>
		<p>Tech Interviews:<input type="checkbox" name="ti" value="x"> Tech Resumes Only:<input type="checkbox" name="tr" value="x"> Watching Equity:<input type="checkbox" name="we" value="x"> Offer EMC:<input type="checkbox" name="emc" value="x"></p>
		<p>Website: <input type="text" name="website" size="24"></p>
		<p>Email: <input type="text" name="email" size="24"></p>
		<p><input type="submit" name="submitButtonName"></p>
	</form>



</body>

</html>

Link to comment
Share on other sites

Inline with what mgallforever said, $_POST is always set. You need not to check it's existence, but it's content. For IE 6's sake (blah), I suggest you implement a hidden input, and check it's value; IE 6 doesn't render submit buttons as $_POST material.

Link to comment
Share on other sites

I suggest you implement a hidden input, and check it's value

 

I'm sorry, I'm not sure I understand, although I think I read something about this earlier. So the hidden input would submit a unique ID to the database, and the database would ignore any information with the same ID? I assume I would need to create another field in my database to deal with that? Am I close??

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.