下面是我的尝试:
if(isset($_POST['recherche'])){
$req = $bdd->prepare('SELECT * FROM produits WHERE Nom_produit LIKE ?');
$req->execute(array('Nom_produit' => $_POST['recherche']));
if($resultat = $req->fetch()){
$url = $resultat['ref_produit'].'.php';
header("location: $url ");}
else { ?>
<script>alert('Produit Non Trouvé');</script>
<?php }
} ?>
我需要帮助!!请
必须将值括在%
中所以改变这一行:
$req->execute(array('Nom_produit' => $_POST['recherche']));
$req->execute(array('%' . $_POST['recherche'] . '%'));
应该可以
like参数需要包含在%
,
$req->execute(array('%' . $_POST['recherche'] . '%'));