Want to insert blank, not zero for integer data type
Posted: Thu Dec 23, 2010 5:49 pm
I have a form with many integer values which are being sent to a db. These rows are set up as a smallint type, with a default of Null and 'Yes' for Null Allowed. The problem I have is that when the form is submitted, any of the fields without a value are being stored as '0', but I just want them to be blank.
I'm using a conditional like the following:
$torque_2 = empty($_REQUEST[Vapor_2]) ? "Null" : $database->mysqlProtect($_REQUEST[Vapor_2]);
I have this in my update statement
Vapor_2 = '$torque_2',
When I look at the debug log, the following line is being executed for the update statement:
Vapor_2 = 'NULL',
But it is still storing a 0 in the db, not a blank entry. All the fields work fine when integers are entered. The only problem I'm having is that the blank rows are turning into zeros.
Any assistance is greatly appreciated.
Update:
I have also tried the statement below, trying to remove the quotes around Null. I'm still getting a zero in the db.
$torque_2 = trim(empty($_REQUEST[Vapor_2]) ? "Null" : $database->mysqlProtect($_REQUEST[Vapor_2]), "'");
I'm using a conditional like the following:
$torque_2 = empty($_REQUEST[Vapor_2]) ? "Null" : $database->mysqlProtect($_REQUEST[Vapor_2]);
I have this in my update statement
Vapor_2 = '$torque_2',
When I look at the debug log, the following line is being executed for the update statement:
Vapor_2 = 'NULL',
But it is still storing a 0 in the db, not a blank entry. All the fields work fine when integers are entered. The only problem I'm having is that the blank rows are turning into zeros.
Any assistance is greatly appreciated.
Update:
I have also tried the statement below, trying to remove the quotes around Null. I'm still getting a zero in the db.
$torque_2 = trim(empty($_REQUEST[Vapor_2]) ? "Null" : $database->mysqlProtect($_REQUEST[Vapor_2]), "'");