I have the following code, which will get values from these 9 variables and insert them in to a table. However, I don't know how to insert NULL
value in to my table. As shown in line 10, if I try to use the keyword NULL
, it consider as a string.
$WorkOrder = $_POST['WorkOrder'];
$Originated = $_POST['Originated'];
$CustID = $_POST['CustID'];
$Customer = $_POST['Customer'];
$Contact = $_POST['Contact'];
$Completed = $_POST['Completed'];
$AccountNum = $_POST['AccountNum'];
$Description = $_POST['Description'];
$Status = $_POST['Status'];
$Status = "NULL"; //Testing with NULL
$insertquery = "INSERT INTO ElectronicShop(WorkOrder, Originated, CustID, Customer, Contact, Completed, AccountNum, Description, Status)
VALUES ('$WorkOrder','$Originated','$CustID','$Customer','$Contact','$Completed','$AccountNum','$Description','$Status')";
$data = sqlsrv_query($connectString, $insertquery) or die(print_r(sqlsrv_errors(SQLSRV_ERR_ALL), true));
I will be getting values for these 9 variables via text boxes in a webpage. So, I can't manually enter NULL
in my query.