This might be a noob question but I can't find anything wrong with my code and I'm still getting mysql errors.
I am using this code to submit a form to a MYSQL database ->
if($forename == '' || $surname == '' || $email == '' || $address1 == '' || $address2 == '' || $terms == ''){
$_SESSION['status'] = 'error';
} else {
$sql = "INSERT INTO dbEntry ('forename','surname','email','address1','address2','terms')
VALUES ('$forename','$surname','$email','$address1','$address2','$terms')" or die(mysql_error());
$results = mysql_query($sql);
if ($results) { echo "Details added."; }
//if (mysql_error()) echo mysql_error();
$_SESSION['status'] = 'success';
}
//Print query for debugging ->
echo $sql;
But it's throwing this error ->
INSERT INTO dbEntry ('forename','surname','email','address1','address2','terms') VALUES ('asd','asd','[email protected]','asd','as','NULL')
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 ''forename','surname','email','address1','address2','terms') VALUES ('asd','as' at line 1
I have created a table to this structure ->
id INT(10) NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
forename VARCHAR(32) NOT NULL,
surname VARCHAR(32) NOT NULL,
email VARCHAR(64) NOT NULL,
address1 VARCHAR(64) NOT NULL,
address2 VARCHAR(64) NOT NULL,
terms TINYINT(1)
I can't see any syntax errors, where am I going wrong? Apologies if I included too much info.
Cheers