I have a working form on my site that successfully inserts the fields into a MySQL database table. I added a new table, basically copied the existing code for the new form, and am getting an error. I've tweaked it a bunch and am baffled.
Here's the form:
<form action="contact.php" method="post">
<input type="hidden" name="submitted" value="true" />
<fieldset>
<label>First Name: <input type="text" name="firstname" required="" /> </label><br />
<label>Last Name: <input type="text" name="lastname" required /> </label><br />
<label>Email Address: <input type="text" name="email" required /> </label><br />
<label>Anniversary Date: <input type="date" name="weddingdate" /> </label><br />
<label>Birthday: <input type="date" name="birthday" /> </label><br />
<label>Business Name: <input type="text" name="business" /> </label><br />
<label>Are You A Chamber Member?: <input type="radio" name="chamber" value="memyes">Yes <input type="radio" name="chamber" value="memno"> No<br />
<label>Comments: <input type="textarea" name="comments" rows="2" cols="50"> </label>
</fieldset>
<input type="submit" value="Enter Me In The Contest!" />
</form>
The contact.php file looks like this:
if (isset($_POST['submitted'])) {
include('dbconnect.php');
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$weddingdate = $_POST['weddingdate'];
$birthday = $_POST['birthday'];
$business = $_POST['business'];
$chamber = $_POST['chamber'];
$comments = $_POST['comments'];
$sqlinsert = "INSERT INTO contest (`firstname`, `lastname`, `email`, `weddingdate`, `birthday`,`business`, 'chamber', 'comments') VALUES ('$firstname', '$lastname', '$email', '$weddingdate', '$birthday', '$business', '$chamber', '$comments')";
if (!mysqli_query($dbcon, $sqlinsert)) {
die('Error adding to database');
}
header('Location: website omitted');
}
I know that it connects properly, I'm using the same connection script for both, and did a test of the connection adding a connection echo message.
All I get with this script is the "Error adding to database" message...
Thanks in advance for the advice and help!
INSERT into) columns'chamber', 'comments'which should be backticks as you did for the others.