1

I want to insert one value into a row. This row has multiple values. When I try to insert show error row-1 does not have default value.

$NoName  = "Record_name";
$no      = "20"; // I want to INSERT this no in row
$sql4    = "INSERT INTO record (date, month, year, $NoName) VALUES ('12-12-2016','12','2017', '$no')";
$result4 = mysqli_query($mysqli,$sql4) or die(mysqli_error($mysqli));

There is some more other rows like no 1, no 2,no 3 i just want to insert no 1 value in new row other values will be empty.

  • 2
    If a column does not have a default value set in the schema, you must set a value for that column on an INSERT – RiggsFolly Jan 05 '17 at 11:43
  • do you want to update or insert? since in your comment you stated update – hungrykoala Jan 05 '17 at 11:45
  • but i want to insert only one. when user record come i will update it by update cmd – user7361961 Jan 05 '17 at 11:45
  • i select all record by date when date change insert new record in new row. when new record come at same date it will update in same date – user7361961 Jan 05 '17 at 11:46
  • According to your query you are trying to INSERT 4 values into 4 different fields? – J2D8T Jan 05 '17 at 11:47
  • 1
    Why do you SHOUT in your questions title? – arkascha Jan 05 '17 at 11:48
  • YES, and there is some other fields too so this error show – user7361961 Jan 05 '17 at 11:50
  • The code you show does not match the question!!! Thats not really very helpful – RiggsFolly Jan 05 '17 at 12:40
  • It is difficult to understand what you want because you are using the word "value" to name several things. Let's try to clarify the names of the items first. A "value" is `20` (and also '$date', '$month' and whatever *values* you put in the `VALUES` part of the query). `date`, `month`, `year` etc are the **columns** of the **table** (the name of the table is `record` in your example). The table has multiple columns and each of its rows has multiple fields. – axiac Jan 05 '17 at 12:41
  • I try to clear please check question updated – user7361961 Jan 06 '17 at 04:39

1 Answers1

1

You can add a default value to that column:

ALTER TABLE record ADD DEFAULT '0000-00-00' FOR date

This is from :

How to set a default value for an existing column

Note that you should use a valid default value.

Community
  • 1
  • 1