Re: Probably a novice error about trying to pass null to mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 19/05/15 08:47, Marcos Almeida Azevedo wrote:
On Tue, May 19, 2015 at 3:45 PM, John Allsopp <john@xxxxxxxxxxxxxxxxx>
wrote:

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?

Would you kindly share info about the table? Specially the constraints


Not sure what you mean about 'constraints' tbh, but here's the table structure cut/pasted if that helps:

1     BOOKING_id     int(10)         UNSIGNED     No     None AUTO_INCREMENT
2     BOOKING_showtimeId     int(10)         UNSIGNED     No None
3     BOOKING_numberOfVehicles     int(10)         UNSIGNED     No     None
4 BOOKING_nameOfPerson varchar(32) utf8_unicode_ci Yes NULL

it's the SQL that's the problem, no?

Hang on .. does this answer your question?

-- phpMyAdmin SQL Dump
-- version 3.5.4
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: May 19, 2015 at 03:58 AM
-- Server version: 5.1.73-cll-lve
-- PHP Version: 5.3.28

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `**redacted**`
--

-- --------------------------------------------------------

--
-- Table structure for table `BOOKING`
--

CREATE TABLE IF NOT EXISTS `BOOKING` (
  `BOOKING_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `BOOKING_showtimeId` int(10) unsigned NOT NULL,
  `BOOKING_numberOfVehicles` int(10) unsigned NOT NULL,
`BOOKING_nameOfPerson` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL .....


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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
-------------------------------------------------------------
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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux