Member Avatar for sakura_fujin

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

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' )

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' )

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.

Member Avatar for sakura_fujin

thank you! it perfectly solved the problem :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.