A
Anonymous
Guest
Hope someone has run across this - I cannot seem to find the solution. I am not certain whether the problem is in code or in the database. I have run into others with the same problem in a couple of other forums, but no one seems to have found an answer.
I have a simple self-contained form (posting to itself). When I insert a new record in the database, it is saving it twice. A few times, rather than saving the same, new data, twice, it saved the new data in one record and duplicated another already existing record, which, of course, make me tend to think it is a DB problem. However, I have set up the same database from scratch on two different servers with two different versions of MySQL, and had the same results.
The form is very simple - in a nut shell:
That's it! Any comments would be appreciated.
I have a simple self-contained form (posting to itself). When I insert a new record in the database, it is saving it twice. A few times, rather than saving the same, new data, twice, it saved the new data in one record and duplicated another already existing record, which, of course, make me tend to think it is a DB problem. However, I have set up the same database from scratch on two different servers with two different versions of MySQL, and had the same results.
The form is very simple - in a nut shell:
Code:
<?PHP
if ($_POST['process'] == 1)
{
Place values from the POST variables back to regular variables and perform some simple validation
Create error messages for fields that do not validate
Set error variable to true if any fields do not validate
if all fields validate (error variable is false)
{
if (!$connect = mysql_connect($HOST, $USER, $PASSWORD))
{
echo ("Error: Did not connect to database!");
}
else
{
mysql_select_db($DBName) or die ('Unable to select database!');
$SaveIt = "INSERT INTO CheckList (NameFirst, NameMid, NameLast, Position, StartDate, Salary, Hourly, Status, App, LCV,DirDep, EmpBook, W4, I9, SSCard) VALUES ('$NameFirst', '$NameMid', '$NameLast', '$Position', '$StartDate', '$Salary', '$Hourly', '$Status', '$App', '$LCV','$DirDep', '$EmpBook', '$W4', '$I9', '$SSCard')";
if(mysql_query($SaveIt))
{
echo('<div style="border:2px solid #000000; background-color:#0000FF; color:#FFFFFF; padding:3px; font-weight:bold; text-align;center;"> Your Data Has Been Saved </div>');
clear($_POST);
}
else
{
echo('<div style="border:2px solid #000000; background-color:#FF0000; color:#FFFFFF; padding:3px; font-weight:bold;"> There was an error in processing the data </div>');
}
}
}
else // nothing has been submitted yet
{
set variables for form
}
}
?>
<html>
Print top of page
<? Print any error messages if fields did not validate ?>
<form name="NewEmpCheck" method="post" action="newemployee.php"> // This form, of course
input fields, ending with:
<input type="hidden" name="process" value="1"></input>
<input type="submit" name="Submit" value="Submit"></input>
<input type="reset" name="reset" value="Reset"></input>
</form>
</html>
That's it! Any comments would be appreciated.