Invalid parameter number: parameter was not defined in

220 views Asked by At

Been stuck here for some time.

I am receiving this error when I try to run the code:

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in /Applications/XAMPP/xamppfiles/htdocs/ProjectWebSite/php/PDO.php on line 111

Line 111 is the first line of the code

$result1 = $query1->execute( array( ':transactionID'=>$transactionID, ':personalID'=>$array['personalID'], 
            ':description'=>$array['description'], ':cost'=>$array['cost'], ':datetime'=>$array['datetime'] )  );




function createTransaction($array){
    $db = connection();
    $stmt = $db->prepare("Select MAX(`transactionID`)+1 AS transactionID FROM transaction ");
    $stmt->execute();
    $transactionID = null;
    $results = $stmt->fetchAll(); 
    foreach ($results as $result) {
        $transactionID =$result['transactionID'];
    }

    if(isset($transactionID)){
        $sql = "INSERT INTO `transaction`(`transactionID`, `personalID`, `description`, `cost`, `dateTime`)"
            . " VALUES (:transactinID,:personalID,:description,:cost,CAST(:datetime AS DATETIME)";
        $query1 = $db->prepare( $sql );

        $result1 = $query1->execute( array( ':transactionID'=>$transactionID, ':personalID'=>$array['personalID'], 
            ':description'=>$array['description'], ':cost'=>$array['cost'], ':datetime'=>$array['datetime'] )  );
        var_dump($result1);
        if ( $result1 ){
     return $transactionID;
        }
             return null;
    }
}
2

There are 2 answers

0
steven On

you have a typo in your query:

:transactinID should be :transactionID

0
fsacer On

It simple you got a typo:
replace:

$sql = "INSERT INTO `transaction`(`transactionID`, `personalID`, `description`, `cost`, `dateTime`)"
            . " VALUES (:transactinID,:personalID,:description,:cost,CAST(:datetime AS DATETIME)";

with:

$sql = "INSERT INTO `transaction`(`transactionID`, `personalID`, `description`, `cost`, `dateTime`)"
            . " VALUES (:transactionID,:personalID,:description,:cost,CAST(:datetime AS DATETIME)";