tags:

views:

46

answers:

4

I have a problem in php code inserting values into database (I use PHPMyAdmin).

My DATABASE has 3 tables:

  1. Member with this fields: MemberID, MemberName
  2. Room with this fields: RoomID, RoomName
  3. Join with this fields: MemberID, RoomID

The idea is to join the member in the room.

My query was

mysql_query("INSERT INTO join (RoomID, MemberID) VALUES ('121', '131')");

but unfortunately it does not work.

+5  A: 

JOIN is a reserved keyword. You might be able to escape it using backticks

INSERT INTO `join` (RoomID, MemberID) VALUES ('121', '131')

but I would suggest renaming the table if possible.

Peter Lang
+1  A: 

Try putting the table name in backticks:

insert into `join` (RoomID,MemberID) values ('121', '131')

Because "join" is an SQL keyword, the parser will get confused if you try to also use it as a name without explicitly making it a name via the ticks.

In the future, you probably don't want to name tables as things that are already SQL keywords - instead, name them something more descriptive, like "RoomsAndMembers" or some such.

Amber
+2  A: 

JOIN is a reserved word in most flavours of SQL.
Try putting the database name before the table name

insert into dbname.join (RoomID,MemberID) ....

Or better yet, rename the table join to something else.

Nifle
A: 

Thank U so much for all of you

It work now :)

Shahd