note 107942 added to mysqli-stmt.bind-param

From: Date: Thu, 15 Mar 2012 18:01:20 +0000
Subject: note 107942 added to mysqli-stmt.bind-param
Groups: php.notes 
Request: Send a blank email to php-notes+get-186693@lists.php.net to get a copy of this message
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> ---- Server IP: 69.147.83.197 Probable Submitter: 163.246.180.96 ---- Manual Page -- http://www.php.net/manual/en/mysqli-stmt.bind-param.php Edit -- https://master.php.net/note/edit/107942 Del: integrated -- https://master.php.net/note/delete/107942/integrated Del: useless -- https://master.php.net/note/delete/107942/useless Del: bad code -- https://master.php.net/note/delete/107942/bad+code Del: spam -- https://master.php.net/note/delete/107942/spam Del: non-english -- https://master.php.net/note/delete/107942/non-english Del: in docs -- https://master.php.net/note/delete/107942/in+docs Del: other reasons-- https://master.php.net/note/delete/107942 Reject -- https://master.php.net/note/reject/107942 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186693) next »