2016-04-30 11 views
2

Ich habe ein Problem mit einer Funktion, sollte Funktion einen Text Basis (phpMyAdmin) oder Menüanzeigen Fehler ..kann nicht null sein - PhP PDO Funktion

Fehlercode gesendet werden:

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'Code' cannot be null

Meine Funktion:

public function UploadInvoice($CONN) 
{ 
    $SubmitOK = '1'; 
    $Core = new Core(); 
    $Core->CheckForEmpty(array('Code'), 'finances.php'); 

    if($SubmitOK == '1') { 
    try { 
     $SQL = 'INSERT INTO Invoices (UserID, Code) VALUES (:UserID, :Code)'; 
     $SQL = $CONN->prepare($SQL); 
     $SQL->execute(array('UserID' => $_SESSION['UserLogin']['ID'], 'Code' => $Code)); 
     $_SESSION['Success'] = 'Successfully submitted your code, Wait for checking multiple payments, your money will be soon on the bill'; 
     header('location: finances'); 
     exit(); 
    } catch(PDOException $e) { 
     echo "Error: " . $e->getMessage(); 
    } 
    } else { 
     $_SESSION['Error'] = 'An error has occurred. Try again!'; 
     header('location: finances'); 
     exit(); 
    } 
} 

Meine Form Code:

<form action="" method="POST"> 
    <input type="text" class="form-control" required="true" minlength="4" name="Code" placeholder="Your ID"> 
    <button type="submit">SEND</button> 
</form> 
+0

Der Fehler eindeutig fest, dass '$ Code' keinen Wert haben –

+0

HALLO @CyberFX: Sie didn‘ t Reagieren Sie auf die unten angegebene Antwort. –

Antwort

1

Sie verpassten ":" in $SQL->execute.... Fügen Sie es mit UserID & Code.

ändern

$SQL->execute(array('UserID' => $_SESSION['UserLogin']['ID'], 'Code' => $Code)); 

Um

$SQL->execute(array(':UserID' => $_SESSION['UserLogin']['ID'], ':Code' => $Code)); 

für weitere Informationen, klicken Sie bitte PDO Statement Execute