note 107942 deleted from mysqli-stmt.bind-param by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 18:05:04 +0000 |
| Subject: | note 107942 deleted from mysqli-stmt.bind-param by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187716@lists.php.net to get a copy of this message | ||
Note Submitter: whojstall11 at gmail dot com
----
I try to have a php file that has a search form that searches by age and the results are going to
give me that age and age less than then it. But everytime run it gives me "Warning:
mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of variables doesn't match
number of parameters in prepared statement in "
My Code:
Html
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var xmlReq;
function processResponse(){
if(xmlReq.readyState == 4){
var place = document.getElementById("placeholder");
place.innerHTML = xmlReq.responseText
}
}
function loadResponse(){
// create an instance of XMLHttpRequest
xmlReq = new XMLHttpRequest();
xmlReq.onreadystatechange = processResponse;
//call server_side.php
xmlReq.open("POST", "findRecords2.php", true);
//read value from the form
// encodeURI is used to escaped reserved characters
parameter = "keyword=" + encodeURI(document.forms["form1"].keyword.value);
//send headers
xmlReq.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
xmlReq.setRequestHeader("Content-length", parameter.length);
xmlReq.setRequestHeader("Connection", "close");
//send request with parameters
xmlReq.send(parameter);
return false;
}
</script>
</head>
<body>
<form method="POST" name="form1" action=""
onsubmit="return loadResponse();">
Search by Age <input type="text" name="keyword">
<input type="button" value="GO"
onclick="loadResponse()">
</form>
<div id="placeholder"></div>
</body>
</html>
This is my Html
<html>
<head>
<title>Display Records</title>
</head>
<body>
<?php
$conn = new mysqli("localhost", "proxy_user",
"my*password", "m9");
if (mysqli_connect_errno()){
echo 'Cannot connect to database: ' .
mysqli_connect_error($conn);
}
else{
//read keyword from user
if(!empty($_POST["keyword"])){
$keyword = "%".$_POST["keyword"]."%";
// create prepared statement
if ($query = mysqli_prepare($conn,
"SELECT FirstName, LastName, Age, Hometown, Job FROM people WHERE UPPER(age) >=
UPPER(age)")) {
// bind parameters
mysqli_stmt_bind_param ($query, "i", $keyword);
//run the query and keep results in $result variable
mysqli_stmt_execute($query);
// bind variables to prepared statement
mysqli_stmt_bind_result($query, $FirstName, $LastName, $Age, $Hometown, $Job);
// fetch values
while (mysqli_stmt_fetch($query)) {
echo "<strong>$LastName, $FirstName</strong> from
$Hometown<br/>age: $Age, occupation: $Job <br/><br/>";
}
//free memory used by a result handle
mysqli_stmt_close ($query);
} else //problem with a query
echo "Error: " . mysqli_error($conn);
} else { //no keyword
echo "No keyword was specified";
}
mysqli_close($conn);
}
?>
</body>