0

I am not using HTML form to get values for this query. I am just inserting a second query once user creates a specific record. However, the second query is not inserting '0' unless I change it to VARCHAR. Others are working fine except for number.

$null = null;
    $query2="insert into npi_program2 (prodID,prodName,TPM,scheme,phases,status,number,date,remarkProg) 
             values('$prodID','$prodName','$null','$null','$null', 0 ,DATE_FORMAT(NOW(),'%b-%d-%Y'),'$null')";
    
    $res1=$db->query($query2);
5
  • You could set the DEFAULT value of the column to NULL Commented Mar 12, 2021 at 4:13
  • Add quote chars in $null = 'null'; (the value must be string, not predefined PHP constant) and remove them in .. , $null, .. (the value must be inserted as predefined MySQL constant, not as string literal). Commented Mar 12, 2021 at 5:06
  • it still isnt able to insert into the database unless I make it as VarChar. Why is it so ? Commented Mar 12, 2021 at 8:53
  • Do you ever bother to check for errors? When a query fails, your system will tell you why. What are you using, mysqli or PDO? Commented Mar 12, 2021 at 10:38
  • There is no error popping. It just inserts for the first query but doesnt for the second(the script above). im using mysqli Commented Mar 15, 2021 at 1:08

1 Answer 1

-1

0 is not equal to null. 0 is false. To insert null in the database, you should pass NULL as a value.

    $query2="insert into npi_program2 (prodID,prodName,TPM,scheme,phases,status,number,date,remarkProg) 
             values($prodID,$prodName,NULL,NULL,NULL, 0 ,DATE_FORMAT(NOW(),'%b-%d-%Y'),NULL)";
    
    $res1=$db->query($query2)
Sign up to request clarification or add additional context in comments.

1 Comment

It still is not inserting into the database. Why is it so?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.