Php 未定义变量:查询错误//
我试着自己解决这个问题,但我累坏了。我使用php在博客网站上工作,遇到一个错误,我想在文章中添加评论: 未定义变量:在C:\wamp\www\entertheletter.dev\fonctions\blog.php的第73行查询 我不会站在它不起作用的地方。当我点击submit按钮时会发生这种情况。这是我的代码: Php指示错误的函数:Php 未定义变量:查询错误//,php,Php,我试着自己解决这个问题,但我累坏了。我使用php在博客网站上工作,遇到一个错误,我想在文章中添加评论: 未定义变量:在C:\wamp\www\entertheletter.dev\fonctions\blog.php的第73行查询 我不会站在它不起作用的地方。当我点击submit按钮时会发生这种情况。这是我的代码: Php指示错误的函数: function recherche(){ global $bdd; extract($_POST);
function recherche(){
global $bdd;
extract($_POST);
$recherche = $bdd->prepare("SELECT id, titre, accroche, publication, image FROM articles WHERE titre LIKE :query OR contenu LIKE :query ORDER by id DESC");
$recherche->execute([
"query" => '%' . $query . '%'
]);
$recherche = $recherche->fetchAll();
return $recherche;
}
注释功能包括:
function commenter() {
if(isset($_SESSION["membre"])) {
global $bdd;
$erreur = "";
extract($_POST);
if(!empty($commentaire)) {
$id_article = (int)$_GET["id"];
$commenter = $bdd->prepare("INSERT INTO commentaires(id_membre, id_article, commentaire) VALUES(:id_membre, :id_article, :commentaire)");
$commenter->execute([
"id_membre" => $_SESSION["membre"],
"id_article" => $id_article,
"commentaire" => nl2br(htmlentities($commentaire))
]);
}
else
$erreur .= "Vous devez écrire du texte";
return $erreur;
}
}
谢谢我认为您不应该对
$\u POST
或$\u GET
使用提取
,因为如果$\u POST
中没有键,PHP将抛出一个未定义的错误。此外,您还需要检查$\u POST
中的数据是否存在
不要直接使用提取($\u POST)
使用$\u POST
function recherche(){
global $bdd;
if(isset($_POST['query'])){
$recherche = $bdd->prepare("SELECT id, titre, accroche, publication, image FROM articles WHERE titre LIKE :query OR contenu LIKE :query ORDER by id DESC");
$recherche->execute([
"query" => '%' . $query . '%'
]);
$recherche = $recherche->fetchAll();
return $recherche;
}
}
我认为您不应该对
$\u POST
或$\u GET
使用extract
,因为如果$\u POST
中不存在键,PHP将抛出一个未定义的错误。此外,您还需要检查$\u POST
中的数据是否存在
不要直接使用提取($\u POST)
使用$\u POST
function recherche(){
global $bdd;
if(isset($_POST['query'])){
$recherche = $bdd->prepare("SELECT id, titre, accroche, publication, image FROM articles WHERE titre LIKE :query OR contenu LIKE :query ORDER by id DESC");
$recherche->execute([
"query" => '%' . $query . '%'
]);
$recherche = $recherche->fetchAll();
return $recherche;
}
}
第73行是什么?“查询”=>“%”$查询。“%”
$query
是否来自$\u POST
?如果是,请检查$\u POST
是否有$\u POST['query']
第73行中的内容?“query”=>“%”$查询。“%”$query
是否来自$\u POST
?如果是,请检查$\u POST
是否有$\u POST['query']