0

I am using bindParam to set values for a MySQL insert. The column in question is an INT (11). It has a default of NULL and null is allowed. However, using bindParam it always receives a 0. I have confirmed that my $_POST['value'] is indeed null.

if(isset($_POST['value'])){
  $stmt = $db->prepare("INSERT INTO table (column) VALUES (:column)");
  $stmt->bindParam(':column',$_POST['value'], PDO::PARAM_INT);
  $stmt->execute();
}

It keeps inserting a '0' instead of NULL if the POST value was ''.

user3822370
  • 641
  • 7
  • 20

1 Answers1

2

You should be matching the complete case (Answer and type) with === (Read More)

Which most likely means that your value is not null like you presume it is.

Ensure it is by checking (pseudo code below):

if(VALUE !=== NULL) {
   value = null
}

But you get the idea there? If not just comment :-)


And as aldanux mentioned in his comment, you have to wrap the column in backticks as it is a reserved word:

INSERT INTO table (`column`) VALUES (:column)
Community
  • 1
  • 1
Darren
  • 13,050
  • 4
  • 41
  • 79