参数号无效,参数无定义

时间:2016-06-30 14:49:55

标签: pdo

尝试在数据库中插入数据,但php抛出无效的参数编号,

$stmt =$pdo->prepare('    
INSERT INTO '.$_POST['option'].' 
(id,title,description,image,date,city,user,price)
values (null,:titl,:desc,:img,:dte,:cty,:user,:prce)');

$stmt->execute( array(
    ':titl'=>$_POST['title'],
    ':desc'=>$_POST['description'],
    ':img'=>$item_img,
    ':dte'=>$date,
    ':city'=>$_POST['city'],
    ':user' =>$_POST['name'], 
    ':prce' =>$price,));

我缺少什么?

1 个答案:

答案 0 :(得分:-1)

问题是,之后的最后$price以及:cty错字。请尝试以下方法:

$stmt->execute(
    array(
     ':titl' => $_POST['title'],
     ':desc' => $_POST['description'],
     ':img' => $item_img,
     ':dte' => $date,
     ':cty' => $_POST['city'],
     ':user' => $_POST['name'], 
     ':prce' => $price
     )
    );