phpmysqlmdb2

mdb2 error with integer = NULL in prepare statement


I have an annoying problem with mdb2 while trying to insert empty values in an integer field.

$query = $conn->prepare("INSERT INTO enquiries 
    (type, idvenue, cname, fname, lname, phone, email, date, guests, budget, comments) 
    VALUES (:party, :venue, :cname, :fname, :lname, :phone, :email, :ddate, :guests, :budget, :options)", 
    array('integer', 'integer', 'text', 'text', 'text', 'text', 'text', 'datetime', 'integer', 'integer', 'text'),
    MDB2_PREPARE_MANIP); 

$result = $query->execute($_POST);

my $_POST array is:

                                [party] => 2
                                [venue] => 
                                [anyve] => checked
                                [cname] => 
                                [fname] => Javi
                                [lname] => Prieto
                                [phone] => 078087028492
                                [email] => ravenfewejp@gmfweail.com
                                [ddate] => 10/10/2011
                                [guests] => 10
                                [budget] => 15
                                [options] => My party!

in the moment that :venue is not empty, it works like a charm, even if :cname (text) is still empty, but when :venue is empty like this I get an undefined error. So I guess is happening only with integer fields, what am I missing?


Solution

  • I realised there's no problem with passing null values to integer fields in this kind of queries. The problem was I was sending one more element in $_POST when venue was empty, so the number of elements in $_POST was different than the number of placeholders.

    Thanks for the help!