Using the highscore tutorial as a base I built a mysql table made up of 10 fields.
when the php sends the request to insert a new entry with only two fields filled:
$query = "INSERT INTO players values (NULL, '$name', '$construct');";
it returns a
QUERY FAILED: Column count doesn't match value count at row 1
It seems that adding entry needs all 10 fields, is this it ?
There are multiple ways to format INSERT statements. One is:
INSERT INTO mytable ('value1', 'value2', 'value3')
You must match the column counts here exactly.
Another is:
INSERT INTO mytable (column1, column2, column3) VALUES ('value1', 'value2', 'value3')
This lets you insert into only a select number of columns. Columns will skip will default to NULL, if they allow NULL values, or a default value (usually zero or an empty string).
The final is:
INSERT INTO mytable SET column1='value1', column2='value2', column3='value3'
Same thing, but better formatting because value/key pairs are grouped. I usually format as:
INSERT INTO mytable
SET
column1='value1'
,column2='value2'
,column3='value3'
Commas on following lines makes it easier to remember they’re there…
Thanks, that’s great help and I am getting closer, no more error but no insert yet.
So I think I need to escape strings I send to mySQL isn’t it. Am I right ?