What is the syntax of inserting a value on a table with CASE statement or IF stmt.
I have PHP form that holds the value, now I wanted to skip the insert value if the text box value is null but I dont know the correct syntax
OR
how can i do this correctly?
I have PHP form that holds the value, now I wanted to skip the insert value if the text box value is null but I dont know the correct syntax
Code:
"insert into table1 (id, category)
values
IF ($cat1 <> null) THEN
({$id}, '{$cat1}'),
ENDIF
IF ($cat2 <> null) THEN
({$id}, '{$cat1}'),
ENDIF";
OR
Code:
$query = "INSERT
WHEN $cat1 <> null then INTO table1 (Cal_ID,DateStamp,Category,Total) VALUES ({$id},NOW(),'{$cat1}',{$Totalcat1})
WHEN $cat2 <> null then INTO table1 (Cal_ID,DateStamp,Category,Total) VALUES ({$id},NOW(),'{$cat2}',null); ";
Comment