Link to home
Start Free TrialLog in
Avatar of encodeme
encodemeFlag for Portugal

asked on

Inserting data into mysql using php

Hi,
I'm inserting  data into a mysql table as below and it works.
However when I add 2 more Null columns to the end of the table, the procedure doesn't work.
I have no problem querying the table with the extra columns added to the query.
Hope you can help.
Thanks

$query = "INSERT INTO competition  (dates,day,type,format,fee,) VALUES
            		
			('".$dates."', '".$day."', '".$type."', '".$format."', '".$fee."')";
  $result = $conn->query($query);

Open in new window

Avatar of Garry Glendown
Garry Glendown
Flag of Germany image

Have you tried the same syntax in the MySQL console?
Have you tried configuring a default value for the new columns, does that correct the behavior?
Avatar of encodeme

ASKER

Hi Garry,
I'm struggling on how to write the query to work in the MYSQL console.... or it doesn't work.

I tried this

INSERT INTO competition  (dates,day,type,format,fee,) VALUES
            		
			(['2011-09-09'], ['sunday'], ['red'], ['green'], ['10'])"

Open in new window

It's to do with the 2 new columns.
If i create a variable, give it a value, change the insert to include the new columns it works.

The column format is as below...I'm sure I'm doing something silly.


2011-09-14-213305.jpg
ASKER CERTIFIED SOLUTION
Avatar of Carlos Llanos
Carlos Llanos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, you don't need to have your default as NULL as you have the NULL checkbox checked already...if you don't insert any information it's already NULL so remove your default = NULL from the draw column, but make sure you keep the NULL checkbox checked.  Do the same with your other column.
Brilliant .. I'm not sure which bit did it but removing the comma and quotations marks made it work.
Curiously in Mysql ..unless I'm wrong, when you change the default field to none, if the Null is ticked, the default fiield is re-set to Null.
many thanks for the help ..enjoy the points :)
Glad to hear it worked ;)