Goog morning all
我的代码明显有问题
这里是:
<fieldset>
<?
if(isset($_POST['requete']) && $_POST['requete'] != NULL){
include "connexion.inc";
$reponse = $bdd->query('SELECT id_piece, piece
FROM tbl_piece
WHERE piece = '.$requete.' ');
while($donnees = $reponse->fetch()){
echo $donnees['id_piece'];
}
}
else{
echo $requete;
}
?>
<form method="post" action="standard.php">
<input type="text" name="requete">
<input type="submit" value="Rechercher">
</form>
</fieldset>
当我在文本框的网页中输入“TL081”之类的内容时,请验证
我接受了这个错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1' in /home/libtronic/www/html/standard.php:48 Stack trace: #0 /home/libtronic/www/html/standard.php(48): PDO->query('SELECT id_piece...') #1 {main} thrown in /home/libtronic/www/html/standard.php on line 48
经过一些搜索,我的问题来自于这个=&gt; '$ requete。'
我试着把.$requete.
或'“。$ requete。”'或者其他但是没有用
有人可以帮我吗?
答案 0 :(得分:1)
尝试更换行
$reponse = $bdd->query('SELECT id_piece, piece
FROM tbl_piece
WHERE piece = '.$requete.' ');
带
$reponse = $bdd->query("SELECT id_piece, piece
FROM tbl_piece
WHERE piece = '".$requete."'");