誰かに助けてもらうことができなかったので、これをもう一度投稿します。jquery オートコンプリートが mysql で正常に動作していますが、それを mysqli の準備済みステートメントに変更しようとしましたが、うまくいきません。誰かが何が間違っているのか教えてもらえますか?
MySQL:
<?php
mysql_connect("localhost","root","");
mysql_select_db("database");
$term=$_GET["term"];
$query=mysql_query("SELECT * FROM products1 where title like '%".$term."%' order by id ");
$json=array();
while($student=mysql_fetch_array($query)){
$json[]=array(
'value'=> $student["title"],
'label'=>$student["title"]
);
}
echo json_encode($json);
?>
MySQLiの準備済みステートメントで試したこと:
<?php
$mydb = new mysqli('localhost', 'root', '', 'database');
$q = '%'.$_POST['term'].'%';
$stmt = $mydb->prepare(" SELECT * from products1 where title LIKE ? ");
echo $mydb->error;
$stmt->bind_param('s', $q);
$stmt->execute();
?>
<?php
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$json[]=array(
'value'=> $student["title"],
'label'=>$student["title"]
);
}
echo json_encode($json);
?>