I made it work after many hours of trying everything I could think of to do... Ultimately, I ended up checking for an empty table first, and then re-creating the table if it was empty.
I'm not sure why this works, but this is my code... it's a bit inelegant, but I could find no better solution. I know that I have not escaped my values. I will later. For now, I simply wanted to solve this problem that I have been wracking my brain about for days.
<?php
$fname = $_POST['fname'];
$mi = $_POST['mi'];
$lname = $_POST['lname'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$con = mysqli_connect("localhost","username","password","database");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
$sql = 'CREATE TABLE employee'
. ' ('
. ' fname text,'
. ' mi varchar(1),'
. ' lname text,'
. ' email varchar(100),'
. ' phone varchar(15)'
. ' add1 varchar(100),'
. ' add2 varchar(100),'
. ' city varchar(100),'
. ' state varchar(25)'
. ' zip varchar(10),'
. ' );';
$sql1 = "INSERT INTO employee (fname, mi, lname, phone, email, add1, add2, city, state, zip,) VALUES ('$fname', '$mi', '$lname', '$phone', '$email','$add1', '$add2', '$city', '$state', '$zip')";
$sql2 = "SELECT * FROM employee";
$sql3 = mysqli_query($con,"SELECT count(*) FROM employee");
if ($sql3 == FALSE) {
trigger_error(mysql_error()." in ".$sql3);
exit();
}
else
{
$result = mysqli_fetch_array($sql3);
}
if($result[0] != 0)
{
mysqli_query($con,$sql1);
}
else
{
mysqli_query($con,$sql);
mysqli_query($con,$sql1);
}
mysqli_close($con);
?>