0

hi,

my php/ mysql query code does not insert data to my table and prints out an error. pls help ive been at this for hours without figuring out what's wrong.

my code:
<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("fppms") or die(mysql_error());

mysql_query("INSERT INTO employee record(Employee ID, Employee type, First name, Last name, Farm location, Farm type) VALUES('34', 'caretaker', 'Michael', 'Hipolito', 'lara', 'nursery' )")
or die(mysql_error());

echo "Data Inserted!";

?>

mysql error message:
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 'record(Employee ID, Employee type, First name, Last name, Farm location, Farm ty' at line 1

any help will be appreciated. thanks

3
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by sakura_fujin
0

The table name and fields that have spaces in the name must be inclosed in single quotes:

INSERT INTO 'employee record'('Employee ID', 'Employee type', 'First Name', 'Last name', 'Farm location', 'Farm type') VALUES('34', 'caretaker', 'Michael', 'Hipolito', 'lara', 'nursery' )
0

The table name and fields that have spaces in the name must be inclosed in single quotes:

INSERT INTO 'employee record'('Employee ID', 'Employee type', 'First Name', 'Last name', 'Farm location', 'Farm type') VALUES('34', 'caretaker', 'Michael', 'Hipolito', 'lara', 'nursery' )

I could be wrong but don't column names and tables have a different type of quote like the following?

INSERT INTO `employee record`(`Employee ID`, `Employee type`, `First Name`, `Last name`, `Farm location`, `Farm type`) VALUES('34', 'caretaker', 'Michael', 'Hipolito', 'lara', 'nursery' )
0

Opps...

cwarn23 is correct about it being the grave (`) and not the single quote ('). I was looking at the code I have and did not pay enough attention to what I was posting..... The example cwarn23 provided is the correct syntax.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.