Page 1 of 1

Strange problem in php5 and mysql 5

Posted: Wed Apr 22, 2009 2:38 am
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

Re: Strange problem in php5 and mysql 5

Posted: Wed Apr 22, 2009 4:21 am
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.

Re: Strange problem in php5 and mysql 5

Posted: Wed Apr 22, 2009 4:25 am
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 ) )

Re: Strange problem in php5 and mysql 5

Posted: Wed Apr 22, 2009 7:45 am
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.....

Re: Strange problem in php5 and mysql 5

Posted: Wed Apr 22, 2009 8:02 am
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

Re: Strange problem in php5 and mysql 5

Posted: Fri Apr 24, 2009 1:01 am
by sangaiah
column name is "login"...