Strange problem in php5 and mysql 5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sangaiah
Forum Newbie
Posts: 6
Joined: Wed Apr 22, 2009 2:30 am

Strange problem in php5 and mysql 5

Post by sangaiah »

I am using PHP5 and MYSQL 5 in RHEL5.

I am facing one strange issue while executing mysql query.

In php code:
mysq_query("insert into fom_orders (login, membership, total, giftcert_discount) values('user1',20,20)");

but i am getting mysql error.. and I have looked the sql log . it was executed like below

insert into fom_orders (, membership, total, giftcert_discount) values('user1',20,20)
1064 : 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 ' membership, total, giftcert_discount '

"login" field is missing. but it is not consistenly happen. but it happens.

Can please help me?

Thanks,
Sangaiah
MasterBeta
Forum Commoner
Posts: 38
Joined: Thu Apr 02, 2009 4:35 am
Location: Lincoln, NE

Re: Strange problem in php5 and mysql 5

Post by MasterBeta »

I'm assuming this isn't your actual code.

Code: Select all

mysq_query("insert into fom_orders (login, membership, total, giftcert_discount) values('user1',20,20)");
I'm also assuming that your insert values (user1 etc.) are dynamic so without seeing your "actual" php code there's no way to help. Your problem most likely lies somewhere else, and tracing it back is where you need to start. You will probably find help here if you give the appropriate information.
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: Strange problem in php5 and mysql 5

Post by Yossarian »

mysq_query("insert into fom_orders (login, membership, total, giftcert_discount) values('user1',20,20)");

That statement is badly formed because you tell it the four columns to update but only pass it 3 values - not the expected 4.

NB With mysql 5+ if 'login' is an autoincremented field - you need to either leave it off completely, or use 0 zero as a value.

values( 0, 'user1', 20, 20 )

(in previous versions you were able to use an empty string values( '', 'user1', 20, 20 ) )
sangaiah
Forum Newbie
Posts: 6
Joined: Wed Apr 22, 2009 2:30 am

Re: Strange problem in php5 and mysql 5

Post by sangaiah »

I am sorry , my insert query is very lengthy , Thats why I have pasted only partial code...

Actually I am passing correct number of values for respecting fields... "login" field is not auto increment field.. "orderid" is an auto increment field... But this issue is not happening always...
Thats is my problem.....

Even my development environment i cannot able to reproduce. but in our production environment is happening..

Thanks for your reply.....
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Re: Strange problem in php5 and mysql 5

Post by miro_igov »

What is the column name before the membership? Try surrounding column names in ` ( `membership`, `total`) to avoid incorrect usage of reserved words. For example if your column is called date and you do insert into table (date) values ('2009-01-01') it will give you error because date is reserved word
sangaiah
Forum Newbie
Posts: 6
Joined: Wed Apr 22, 2009 2:30 am

Re: Strange problem in php5 and mysql 5

Post by sangaiah »

column name is "login"...
Post Reply