存在数据库条目,但search_result返回false

<?php
require 'database.php';

//if (!empty($_POST['search'])):

$sql1 = "SELECT * FROM cookies2 WHERE  cookie LIKE '%".$_POST['search']."%'";

$request1 = $conn->prepare($sql1);
$request1->bindparam(':search', $_POST['search']);

$request1->execute();
$result1 = $request1->fetch(PDO::FETCH_ASSOC);
var_dump($request1);
$ff = $result1['cookie'];
//endif;
?>
<html>


<meta charset="utf-8" /> 
<body>


<form action="comments.php" method="post"/>
<input type="text" name="search" placeholder="search for user comments"/>
<input type="submit"/>

    <?php
    if(!empty($request1)):
    while($search_result = $request1->fetch(PDO::FETCH_ASSOC)){ 
    var_dump($search_result);?>

    <h1>baaaaaa</h1>
    <p><?= $search_result['cookie']?></p>
    <h3><?= $search_result['comment']?></h3><?php }


 endif;
?>



</body>
</html>

So I am writing script for my cookie app. And This script works just fine in another page.php to search for cookies but I been stuck 2 days and loop wont start and search_result return false most of the times. Is my bindparam wrong or have I missed some basic indenting? I want to have this table for user comments on specific cookies. to search for. I am writing this in danger get banned my last question probably. I like stack overflow but its not for beginners I guess. All feedback is welcome I don't know what is wrong when almost identic script worked before this. regards. don

ps baaaa is showing sometimes and the loop don't show and even though I have ie bak in table nothing shows, and I have been looking for similar posts but nothing is as my problem.

Change your query statements like this:

$sql1 = "SELECT * FROM cookies2 WHERE  cookie LIKE :search"; // Changed line no.1

$request1 = $conn->prepare($sql1);
$request1->bindparam(':search', "%".$_POST['search']."%", PDO::PARAM_STR); // Changed line no.2

$request1->execute();
$result1 = $request1->fetch(PDO::FETCH_ASSOC);
var_dump($request1);

For more details: See

You can only bind to placeholders in prepared statements; you have no placeholder

So create the placeholder without quotes, because binding handles that for you cleanly.

$sql1 = "SELECT * FROM cookies2 WHERE  cookie LIKE :search";

and then wrap the search argument in the wildcards before binding

$request1->bindparam(':search', '%' . $_POST['search'] . '%');