PHP Code:
<input type="text" name="score1"/>
<input type="text" name="score2"/>
<?php
if(isset($_POST['processForm'])) {
// VERY IMPORTANT RULE:
// a "hard" exit(); in your code is a VERY bad idea,
// unless you explicitly add notifications before you exit.
// exit() does NOT break out of a loop, it "shuts down" PHP.
// You'll end up with blank white pages,
// and no reference to what or where it happened.
// create a tmp var that you can toggle
$tmpProcess=TRUE;
// I assume, based on your form that this SHOULD BE 'score1' and not 'score'
$score1 = $_POST['score1'];
// I assume that you need this var set as well, based on the form above ??
$score2 = $_POST['score2'];
// these variables look backwards... check 1 -> report 2 ?
if (empty($score1)) {
$tmpProcess=FALSE;
echo "You haven't entered a score for score2";
}
else if (empty($score2)) {
$tmpProcess=FALSE;
echo "You haven't entered a score for score1";
}
// by changing the tmp var above, you can avoid running the insert query
// if you have blank values. I'm guessing you need both
// $score1 and $score2 to properly insert?
if ($tmpProcess===TRUE) {
#connection here
$sql = "INSERT STATEMENT HERE";
mysql_query($sql);
echo "success message";
} // end $tmpProcess
}
?>
</form>
<div id="footer">Footer</div>
Bookmarks