Probably a novice error about trying to pass null to mysql
| From: | John Allsopp | Date: | Tue, 19 May 2015 07:45:24 +0000 |
| Subject: | Probably a novice error about trying to pass null to mysql | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-324910@lists.php.net to get a copy of this message | ||
Hi
I'm trying to write a blank mysql record, so I have
$tBookingId = $myBookingController->save($myShowtimeController->getShowtimeId(), 1, null, null, null, null, null, null, null, null, 0, 0);
and in myBookingController
function save($pBOOKING_showtimeId, $pBOOKING_numberOfVehicles, $pBOOKING_nameOfPerson ...)
{
$toReturn = false;
$this->iBOOKING_showtimeId = $pBOOKING_showtimeId;
$this->iBOOKING_numberOfVehicles = $pBOOKING_numberOfVehicles;
$this->iBOOKING_nameOfPerson = $pBOOKING_nameOfPerson;
..
$sql = "INSERT into BOOKING values (null, $pBOOKING_showtimeId, $pBOOKING_numberOfVehicles, \"$pBOOKING_nameOfPerson\ .... )";and when I look at that $sql, it's INSERT into BOOKING values (null, , 1, "", ...) So, it's failing because the function $myShowtimeController->getShowtimeId() returns NULL, but that's not reflected in the SQL, so my first question is, do I really have to write: if ($pBOOKING_showtimeId===null)
{
$sql .= "null, ";
} else
{
$sql .= "$pBOOKING_showtimeId, ";
}
.. and my second question is that none of the string variables are going to come out NULL either, they'll end up as blank strings.
I'm really just trying to avoid having to write the above fix for all those variables.
Where am I wrong and why?
Cheers
J
--
-------------------------------------------------------------
John Allsopp, Online marketing, web development & social media
Learn Twitter marketing for the smaller enterprise: http://www.surgemarketing.co.uk/twitterForTheSmallEnterprise.php
http://www.surgemarketing.co.uk
http://www.johnallsopp.co.uk
http://www.amilliontweaks.co.uk
Tel: 01723 376477 / 07762 941921
Twitter: @JohnAllsoppIM