我在使用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
請打開手冊。 –