jeudi 21 février 2019

PHP Integrity Contraint Violation - Column Cannot be NULL [duplicate]

So i've made a script where the user has to click over 60 different checkboxes depending on what features a car has. I then post these results to another page here it's splitting the results into different sections as i have 6 different tables in my database for different categories. Once the data has been split I and put into variables I then create the queries and post them to the database. However i keep getting multiple errors and i'm not sure why.

    //categoryAdditional
if (isset($_POST['adpativeLEDLights'])) { $ledLights = 1; } else { $ledLights = 2; }
if (isset($_POST['appearancePack'])) { $appearancePack = 1; } else { $appearPack = 2; }
if (isset($_POST['cambeltChanged'])) { $cambeltChanged = 1; }
if (isset($_POST['cityPack'])) { $cityPack = 1; }
if (isset($_POST['dabRadio'])) { $dabRadio = 1; }
if (isset($_POST['dvdScreensRear'])) { $dvdScreensRear = 1; }
if (isset($_POST['laneDepartureWarning'])) { $laneDepartureWarning = 1; }
if (isset($_POST['lezCompliant'])) { $lezCompliant = 1; }
if (isset($_POST['parkAssistancePack'])) { $parkAssistancePack = 1; }
if (isset($_POST['powerTailGate'])) { $powerTailGate = 1; }
if (isset($_POST['windDeflectors'])) { $windDeflectors = 1; }

    $additionalQuery = $conn->prepare('
        INSERT INTO categoryAdditional (
            vehicleReg, adaptiveLedLights, appearancePack, cambeltChanged, cityPack, dabRadio, dvdScreensRear, laneDepartureWarning, lezCompliant, parkAssistancePack, powerTailGate, windDeflectors 
        ) VALUES (
            :reg, :ledLights, :appearancePack, :cambelt, :city, :dab, :dvdscreens, :laneDeparture, :lez, :parkAssist, :powerTailGate, :windDeflectors           )
        ');

    $additionalQuery->execute(array(
            ':reg' => $vehicleReg,
            ':ledLights' => $ledLights,
            ':appearancePack' => $appearancePack,
            ':cambelt' => $cambeltChanged,
            ':city' => $cityPack,
            ':dab' => $dabRadio,
            ':dvdscreens' => $dvdScreensRear,
            ':laneDeparture' => $laneDepartureWarning,
            ':lez' => $lezCompliant,
            ':parkAssist' => $parkAssistancePack,
            ':powerTailGate' => $powerTailGate,
            ':windDeflectors' => $windDeflectors
        )
    );

The error(s) i'm getting are;

Notice: Undefined variable: appearancePack in /homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 35

Notice: Undefined variable: cambeltChanged in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 36

Notice: Undefined variable: cityPack in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 37

Notice: Undefined variable: dabRadio in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 38

Notice: Undefined variable: dvdScreensRear in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 39

Notice: Undefined variable: laneDepartureWarning in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 40

Notice: Undefined variable: lezCompliant in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 41

Notice: Undefined variable: parkAssistancePack in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 42

Notice: Undefined variable: powerTailGate in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 43

Notice: Undefined variable: windDeflectors in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 45

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: >Integrity constraint violation: 1048 Column 'appearancePack' cannot be null' in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php:46 Stack trace: #0 >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php(46): PDOStatement->>execute(Array) #1 {main} thrown in >/homepages/38/d735513801/htdocs/connectPortal/stepThree.php on line 46

The undefined variable's I think is because on my IF statements i haven't got an ELSE statement which I've started adding as you can see. However the last error about the appearancePack cannot be NULL is the third column in my table so I've no idea why it can't be NULL. All the rows are set to Integer's.

Here is what my table looks like; This is what my table looks like with the 'appearancePack' row

Aucun commentaire:

Enregistrer un commentaire