被困在这里一段时间。
我在尝试运行代码时收到此错误:
警告:PDOStatement :: execute():SQLSTATE [HY093]:参数无效 number:参数未定义 /Applications/XAMPP/xamppfiles/htdocs/ProjectWebSite/php/PDO.php on 第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;
}
}
答案 0 :(得分:1)
您的查询中有拼写错误:
:transactinID
应为:transactionID
答案 1 :(得分: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)";