0

Hi I'm having problems inserting into my local database, I have an established connection as I can query using "SELECT * FROM contact", but I cannot insert using the following code

$query1 = "INSERT INTO 'contact' ('e-mail', 'subject', 'body')
VALUES('email@gmail.com', 'another question', 'Just asking?')";

This is the error it's giving me - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''e-mail', 'subject', 'body')

If anyone could kindly assist?

MG97
  • 87
  • 1
  • 11

1 Answers1

1

Try this. no need for ' around table name

$query1 = "INSERT INTO contact (`e-mail`, `subject`, `body`)VALUES('email@gmail.com', 'another question', 'Just asking?')";
MG97
  • 87
  • 1
  • 11
Jason Delaney
  • 458
  • 8
  • 21
  • Error: INSERT INTO contact ('e-mail', 'subject', 'body') VALUES('email@gmail.com', 'another question', 'Just asking?') You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''e-mail', 'subject', 'body') ######Still receive this error – MG97 Mar 23 '17 at 16:47
  • make sure colunm names e-mail are the same as your database – Jason Delaney Mar 23 '17 at 16:48
  • your `'` is `\``? (shift+~ key) `$query1 = "INSERT INTO \`contact\` (\`e-mail\`, \`subject\`, \`body\`)VALUES('email@gmail.com', 'another question', 'Just asking?')";` – Sheridan Mar 23 '17 at 16:50
  • It was the fact that I didn't use backticks for columns, i was unaware of this, I'm following a course right now that has been really good however it appears that things have changed since, thank you to everyone! – MG97 Mar 23 '17 at 16:54