2

I have a problem with one function, function should be sent a text to base (phpmyadmin), or menu displays error..

Error code:

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

My function:

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();
  }
}

My 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>
2
  • The error clearly states that $Code have no value Commented Apr 30, 2016 at 7:50
  • HI @CyberFX: You Didn't Respond To The Answer Given Below. Commented May 5, 2016 at 9:43

1 Answer 1

1

You Missed ":" in $SQL->execute.... Append it with UserID & Code.

Change

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

To

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

For More info, Please click PDO Statement Execute

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.