I have spent days trying to figure how to get form data on my webpage to insert into my employee table on the forklift database mssql. when i click submit on the form it refreshes the page with Connection established but no data in the database.
<?php
/* Connect using Windows Authentication. */
$serverName = "EXAMPLE";
$connectionOptions = array("Database"=>"FORKLIFT");
/* Connect using Windows Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionOptions);
if($conn)
{
echo "Connection established.<br />";
}
else
{
echo "Connection could not be established.<br />";
die(print_r(sqlsrv_errors(), true));
}
if(empty($_POST) === false && empty($errors)=== true)
{
//assign form input to variables
$FIRSTNAME = $_POST["FIRSTNAME"];
$LASTNAME = $_POST["LASTNAME"];
$DATEOFBIRTH = $_POST["DATEOFBIRTH"];
$PHONENUMBER = $_POST["PHONENUMBER"];
$ADDRESS = $_POST["ADDRESS"];
/*Insert data.*/
$INSERT_ROW = $query = "INSERT INTO
EMPLOYEE(FIRSTNAME,LASTNAME,DATEOFBIRTH,PHONENUMBER,ADDRESS)
VALUES ('$FIRSTNAME','$LASTNAME','$DATEOFBIRTH','$PHONENUMBER','$ADDRESS')";
$result = sqlsrv_prepare($conn,$query)or die('Error querying MSSQL
database');
sqlsrv_execute($result);
}
?>
HTML
<form name="submit" action="employee.php" method="POST" >
<h2>Register New Member</h2>
<table border="0">
<tr>
<td>FIRSTNAME</td>
<td>
<input type="text" name="FIRSTNAME" id="FIRSTNAME"/>
</td>
</tr>
<tr>
<td>LASTNAME</td>
<td>
<input type="text" name="LASTNAME" id="LASTNAME"/>
</td>
</tr>
<tr>
<td>DATE_OF_BIRTH</td>
<td>
<input type="date" name="DATE_OF_BIRTH" id="DATE_OF_BIRTH"/>
</td>
</tr>
<tr>
<td>PHONENUMBER</td>
<td>
<input type="text" name="PHONENUMBER" id="PHONENUMBER"/>
</td>
</tr>
<tr>
<td>ADDRESS</td>
<td>
<input type="text" name="ADDRESS" id="ADDRESS"/>
</td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" name="submit" value="REGISTER"/></td>
</tr>
</table>