2015-06-09 75 views
-1
中定義

在此處卡住了一段時間。參數編號無效:參數未在

當我嘗試運行代碼我收到此錯誤:

警告:PDOStatement對象::執行():SQLSTATE [HY093]:無效參數 數:參數沒有在 定義/應用/XAMPP/xamppfiles/htdocs/ProjectWebSite/php/PDO.php上 線111

線111是代碼

$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; 
    } 
} 
的第一行

回答

1

你在查詢一個錯字:

:transactinID應該是:transactionID

+0

哇男人......謝謝 –

0

它簡單,你有一個錯字:
取代:

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

有:

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