Reputation: 30238
I have the following PHP code:
$query = array(
$this->userid_to,
$userid_to,
$this->gibid,
$this->card_type,
$message,
$isDeck
);
print_r($query);
$sql = "INSERT INTO
cards (
userid_from,
userid_to,
gibid,
card_type,
message,
isDeck,
createdon
) VALUES (?,?,?,?,?,?,current_timestamp)";
Db::execute($sql,$query);
$this->cardid=Db::getLastInsertId();
While running this I am passing $message variable as blank so I am getting this error:
Array (
[0] => 1
[1] => 4
[2] => 0
[3] => V
[4] =>
[5] => N )
Fatal error: Uncaught exception
'PDOException' with message 'Database
error [23000]: Column 'message' cannot
be null, driver error code is 1048' in
/var/www/ryapi/Db.php:179 Stack trace:
0 /var/www/ryapi/Db.php(54): Db::_query('INSERT INTO car...',
Array)
1 /var/www/ryapi/card.php(79): Db::execute('INSERT INTO car...',
Array)
2 /var/www/ryapi/index.php(173): Card->givecard('4', NULL, NULL)
3 {main} thrown in /var/www/ryapi/Db.php on line 179
If I want to pass $message
as blank, how can I remove this error.
Upvotes: 0
Views: 339
Reputation: 1
Two solutions - Make "message" column nullable in database, if you really expect "null" for message value. You need to be careful in doing so, if it breaks other part of application. - Pass dummy value like whitespace - i.e " " OR string like "none" or any string which will denote that there is really no message
Upvotes: 0
Reputation:
I think this column must not be (null). Check if you can make the column nullable.
(null) and empty string are not the same "values".
Upvotes: 1
Reputation: 723448
Make sure $message
is really an empty string and not the value NULL
.
Upvotes: 0