in a php file that use this line of code to insert some text in the table TABONE
mysql_query("INSERT INTO `TABONE` VALUES ('$q1', '$q2', '$q3', '$q4', '$q5')") ;
the code work fine because “we receive 5 variables and this table contain 5 columns“
but sometimes we receive 5 variables for a table that contain only 3 columns and in this case we just want to insert the first 3 variables (‘$q1’, ‘$q2’, ‘$q3’)in the 3 columns.
in this case
mysql_query("INSERT INTO `TABONE` VALUES ('$q1', '$q2', '$q3', '$q4', '$q5')") ;
doesn’t work – How to correct this.
As stated in the manual:
Therefore, you can:
name the columns and omit those for which you want default values:
Or, if you prefer the
SETsyntax:explicitly set the other columns to their default values with the
DEFAULTkeyword: