0
try {
                    print_r($con->_con);
                    $save_transaction1 = $con->_con->prepare("INSERT INTO hpay "
                            . "(amt,entryby,orno,chrgcode) VALUES "
                            . "(:amt,:entryby,:orno,:chrgcode)");
                    $save_transaction1->bindValue(":amt", $tenderedamount, PDO::PARAM_STR);
                    $save_transaction1->bindValue(":entryby", $_SESSION['account_id'], PDO::PARAM_STR);
                    $save_transaction1->bindValue(":orno", $ornumber, PDO::PARAM_STR);
                    $save_transaction1->bindValue(":chrgcode", $chargecode, PDO::PARAM_STR);
                    if ($save_transaction1->execute()) {
                        echo "asd";
                    } else {
                        print_r($con->_con->errorInfo());
                    }
                } catch (PDOException $e) {
                    echo $e;
                }

I have this to insert data in my database. But what I am getting is not what I expect it is not inseting in database, the print_r() i get is

Updated Error

PDO Object ( ) Array ( [0] => 00000 [1] => 0 [2] => ((null)[0] at (null):0) [3] => )

Giant
  • 1,619
  • 7
  • 33
  • 67
  • https://stackoverflow.com/questions/8776344/how-to-view-query-error-in-pdo-php – Mike May 30 '17 at 05:32
  • what is $dbh and $con? – Exprator May 30 '17 at 05:37
  • @Exprator sorry i didnt change that from the example i found in SO i change it and posted the error – Giant May 30 '17 at 05:39
  • @Exprator what is the meaning of error? i dont understand the error – Giant May 30 '17 at 05:40
  • the error means the variable that you are passing in the bindvalue is blank, try to print and check if those have values in it – Exprator May 30 '17 at 05:41
  • @Exprator i get `PDO Object ( ) tenderedamount 95.00id 8ornumber 1chargecode W14-213201Array ( [0] => 00000 [1] => 0 [2] => ((null)[0] at (null):0) [3] => )` meaning all values have value but still not inserting because the echos of 4 values are `tenderedamount 95.00id 8ornumber 1chargecode W14-213201` it is not null – Giant May 30 '17 at 05:45
  • try to check the database fields type, keep all varchar with 255 length – Exprator May 30 '17 at 05:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/145411/discussion-between-giant-and-exprator). – Giant May 30 '17 at 05:57

1 Answers1

1

Error

Array ( [0] => 00000 [1] => 0 [2] => ((null)[0] at (null):0) [3] => )

Means that there are not null columns and are inserted with null meaning that you cant insert null into not null columns

Solution:

Change not null columns into null columns

Giant
  • 1,619
  • 7
  • 33
  • 67