我对使用mysql编写pdo语句有问题。执行查询时,它会将我使用 bindParam()
方法。下面是代码,下面是查询执行结果的屏幕。我怎样才能解决这个尴尬的问题?我是pdo的新手!
php(这是使用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';
}
}
PHP2(这是管理所有数据库操作的类的函数)
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';
}
}
这是查询执行后的结果屏幕
1条答案
按热度按时间nr7wwzry1#
尝试删除绑定部分周围的单引号