I'm a little at a loss here. I'm trying to get this form to submit to a MYSQL server (hosted on my machine), but it keeps throwing this error:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Would anyone be willing to take a look and see if you can spot the error?
here is my SQL code:
<?php
//Establish value variables
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$address=$_POST['address'];
$zipcode=$_POST['zipcode'];
$state=$_POST['state'];
$city=$_POST['city'];
$petname=$_POST['petname'];
$petType="";
$neut="";
if(isset($_POST['neut'])){ $neut = $_POST['neut']; }
if (isset($_POST['petType'])){$petType = $_POST['petType']; }
//establish connection
$con = mysql_connect("localhost","root","pwdpwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("pet_shop", $con);
//initializing the $error variable + array holding errors
$error = array ();
if (empty($firstName)) { $error[]='You forgot to enter your first name!'; }
if (empty($lastName)) { $error[]='You forgot to enter your last name!'; }
if (empty($email)) { $error[]='You forgot to enter your email!'; }
if (empty($phone)) { $error[]='You forgot to enter your phone number!'; }
if (empty($address)) { $error[]='You forgot to enter your address!'; }
if (empty($city)) { $error[]='You forgot to enter your city!'; }
if (empty($state)) { $error[]='You forgot to enter your state!'; }
if (empty($petname)) { $error[]='You forgot to enter your pet name!'; }
if(!empty($error))
{
die(implode('<br />', $error)); //stops script and prints errors
}
if(!$error) {
//Insert information into columns
$sql="INSERT INTO grooming (firstName, lastName, email, phonenumber, address, zip, state, city, petname, PetType, NeuteredOrSpayed)";
}
//enter into if everything is okay
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error($con));
}
else
{
echo "<span>Appointment added!</span>";
}
//close connection
mysql_close($con);
?>
</body>
<br />
<a href="grooming.php"><button class="backButtn" id="backButtn">Back</button></a>
</html>
Notes: 'petType' refers to a set of radio buttons and 'neut' is a checkbox.