donglei1616 2018-05-12 02:36
浏览 69
已采纳

PHP PDO查询执行不保存传递的数据

I've a problem with PDO prepared statements using mysql. When the query is executed it will save into the preposed table the placeholders that I've binded using the bindParam() method. Here is the code and here is a screen of the result of the execution of the query. How i can solve this embaracing problem? I'm a newbie on PDO!

PHP (This is the controller that is called using ajax).

if(isset($_POST['code'])){

$code = filter_var($_POST['code'],FILTER_SANITIZE_STRING);    
$qty = filter_var($_POST['quantity'],FILTER_SANITIZE_STRING);  
$brand = filter_var($_POST['brand'],FILTER_SANITIZE_STRING);
$article_name = filter_var($_POST['artName'],FILTER_SANITIZE_STRING);  
$price = filter_var($_POST['price'],FILTER_SANITIZE_STRING);
$article_type = filter_var($_POST['artType'],FILTER_SANITIZE_STRING); 
$note = filter_var($_POST['note'],FILTER_SANITIZE_STRING);    

$save = $core->insert_article($code,$qty,$brand,$article_name,$price,$article_type,$note);    

if($save){
echo 'ok';    
} else {
echo 'error';    
}

}

PHP 2 (this is the function of the class who manage all the database operations)

public function insert_article($code,$qty,$brand,$article_name,$price,$article_type,$note){

$db = $this->init_db();    

$sql = "INSERT INTO products (cod_articolo, pezzi_disponibili, marca, nome_articolo, prezzo, tipologia_articolo, note) VALUES (':cod_articolo',':pezzi_disponibili',':marca',':nome_prodotto',':prezzo',':tipologia_articolo',':note')";    
$stmt = $db->prepare($sql);    

$stmt->bindParam(':cod_articolo',$code,PDO::PARAM_STR);
$stmt->bindParam(':pezzi_disponibili',$qty,PDO::PARAM_STR);
$stmt->bindParam(':marca',$brand,PDO::PARAM_STR);
$stmt->bindParam(':nome_articolo',$article_name,PDO::PARAM_STR);
$stmt->bindParam(':prezzo',$price,PDO::PARAM_STR);
$stmt->bindParam(':tipologia_articolo',$article_type,PDO::PARAM_STR);
$stmt->bindParam(':note',$note,PDO::PARAM_STR);

if($stmt->execute()){
echo 'ok';    
} else {
echo 'error';    
}    

}

This is the screen of the results after that the query is executed table after query execution

展开全部

  • 写回答

1条回答 默认 最新

  • douxuan4556 2018-05-12 02:41
    关注

    Try removing the single quotes surrounding the binding part

    $sql = "INSERT INTO products (cod_articolo, pezzi_disponibili, marca, nome_articolo, prezzo, tipologia_articolo, note) VALUES (:cod_articolo,:pezzi_disponibili,:marca,:nome_prodotto,:prezzo,:tipologia_articolo,:note)";    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥40 selenium访问信用中国
  • ¥15 电视大赛投票系统的c语言代码怎么做
  • ¥20 在搭建fabric网络过程中遇到“无法使用新的生命周期”的报错
  • ¥15 Python中关于代码运行报错的问题
  • ¥500 python 的API,有酬谢
  • ¥15 软件冲突问题,软件残留问题
  • ¥30 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥50 有没有人会写hLDA,有偿求写,我有一个文档,想通过hLDA得出这个文档的层次主题,有偿有偿!
  • ¥15 alpha101因子里哪些适合crypto?
  • ¥15 ctrl win alt 键一直触发
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部