我试图使用PDO和PHP在mysql表中插入数据。我每次收到42000错误都会收到,我无法理解原因。 这里有我的代码:
$getOriginalOffer = $db->prepare("select * from original_offer where id = :id");
$getOriginalOffer->bindParam(":id",$idOriginal);
$getOriginalOffer->execute();
$originalOffer = $getOriginalOffer->fetch(PDO::FETCH_ASSOC);
$publishOfferQuery = "insert into published_offer (codice_onshop,nome,inbreve,anteprima,galleria1,galleria2,galleria3,galleria4,prezzo,tp_prezzo,bonus_usabile,proposta,condizioni,prenotare,categoria,description,keywords,valido_da,valido_a";
$publishOfferQuery .= "values (:co,:no,:ib,:an,:g1,:g2,:g3,:g4,:pr,:tp,:bo,:pro,:con,:pre,:ca,:de,:ke,:da,:a)";
$publishOffer = $db->prepare($publishOfferQuery);
$publishOffer->bindParam(':co', $onshopCode);
$publishOffer->bindParam(':no' ,$originalOffer['nome']);
$publishOffer->bindParam(':ib' ,$originalOffer['inbreve']);
$publishOffer->bindParam(':an' ,$originalOffer['anteprima']);
$publishOffer->bindParam(':g1' ,$originalOffer['galleria1']);
$publishOffer->bindParam(':g2' ,$originalOffer['galleria2']);
$publishOffer->bindParam(':g3' ,$originalOffer['galleria3']);
$publishOffer->bindParam(':g4' ,$originalOffer['galleria4']);
$publishOffer->bindParam(':pr' ,$originalOffer['prezzo']);
$publishOffer->bindParam(':tp' ,$originalOffer['tp_prezzo']);
$publishOffer->bindParam(':bo' ,$originalOffer['bonus']);
$publishOffer->bindParam(':pro',$originalOffer['proposta']);
$publishOffer->bindParam(':con',$originalOffer['condizioni']);
$publishOffer->bindParam(':pre',$originalOffer['prenotare']);
$publishOffer->bindParam(':ca' ,$originalOffer['categoria']);
$publishOffer->bindParam(':de' ,$originalOffer['description']);
$publishOffer->bindParam(':ke' ,$originalOffer['keywords']);
$publishOffer->bindParam(':da' ,$oggi);
$publishOffer->bindParam(':a' ,$a);
if($publishOffer->execute()) {
echo "<p style='color: red; font-weight: bold; text-align: center'>Operazione effettuata con successo. Attendi 5 secondi...</p>";
sleep(5);
header("location: ../elenco_offerte.php");
}
我也尝试使用函数$ quote发送参数,因为这些参数中也有html标签,但它给了我:
Strict Standards: Only variables should be passed by
我非常绝望!我怎么解决这个问题?
先谢谢!
答案 0 :(得分:2)
您永远不会关闭列级别的括号。
$publishOfferQuery = "insert into published_offer (codice_onshop,nome,inbreve,anteprima,galleria1,galleria2,galleria3,galleria4,prezzo,tp_prezzo,bonus_usabile,proposta,condizioni,prenotare,categoria,description,keywords,valido_da,valido_a"; <--- here
应该是
$publishOfferQuery = "insert into published_offer (codice_onshop,nome,inbreve,anteprima,galleria1,galleria2,galleria3,galleria4,prezzo,tp_prezzo,bonus_usabile,proposta,condizioni,prenotare,categoria,description,keywords,valido_da,valido_a)";
或在values
...
$publishOfferQuery .= " ) values (:co,:no,:ib,:an,:g1,:g2,:g3,:g4,:pr,:tp,:bo,:pro,:con,:pre,:ca,:de,:ke,:da,:a)";
或者。
您的查询就是
insert into published_offer
(codice_onshop,nome,inbreve,anteprima,galleria1,galleria2,galleria3,galleria4,prezzo,tp_prezzo,bonus_usabile,proposta,condizioni,prenotare,categoria,description,keywords,valido_da,valido_a
values (:co,:no,:ib,:an,:g1,:g2,:g3,:g4,:pr,:tp,:bo,:pro,:con,:pre,:ca,:de,:ke,:da,:a)
答案 1 :(得分:2)
您必须将)
放在MySQL查询的末尾:
$publishOfferQuery = "insert into published_offer (codice_onshop,nome,inbreve,anteprima,galleria1,galleria2,galleria3,galleria4,prezzo,tp_prezzo,bonus_usabile,proposta,condizioni,prenotare,categoria,description,keywords,valido_da,valido_a");