我在使用bind_param()
时不断收到跟随错误,并试图用一切方法解决它,但似乎没有任何效果。当在php中使用bind_param()时出现错误
Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables
这里是我的代码
$output = '';
$output2 = '';
$output3 = '';
if(isset($_POST['search'])) {
$search = $_POST['search'];
$search = preg_replace("#[^0-9a-z]i#","", $search);
if ($stmt = $db->prepare("SELECT * FROM Users WHERE name LIKE '%$search%'")){
$stmt->bind_param("s", $search);
$count = $stmt->num_rows();
$stmt->execute();
if($count == 0){
$output = "There was no search results!";
}else{
while ($rows = $stmt->num_rows) {
$name = $row ['name'];
$location = $row ['location'];
$gender = $row ['gender'];
$date_of_birth = $row ['date_of_birth'];
$picture = $row['url'];
$output .='<form action="header.php" method="post"><div class="row"><div class="col-sm-3">'.$name.'<br>'.$location.'<br>'.$gender.'<br>'.$date_of_birth.'</div>';
$output2 = '<div class="col-sm-3"><img src="upload/'.$picture.'"width="180" height="144" /></div></div>';
$output3 = '<input id="add_friend" name= "addfriend" type="submit" value="Add As Friend" /></form>';
}
}
}
你没有占位符,但绑定一个值。 – Qirel
请详细解释一下 – Rebekah
请打开手册。 –