whojstall11 Posted March 16, 2012 Share Posted March 16, 2012 My code keeps giving me and error on 22 saying: Warning: mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of variables doesn't match number of parameters in prepared statement in E:\xampp\htdocs\m9\findRecords2.php on line 22 <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 age <='" . $keyword ."' " )) { // 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> </html> keyword and age are ints can anybody please help Quote Link to comment https://forums.phpfreaks.com/topic/259084-php-number-of-variables-error/ Share on other sites More sharing options...
requinix Posted March 16, 2012 Share Posted March 16, 2012 if ($query = mysqli_prepare($conn, "SELECT FirstName, LastName, Age, Hometown, Job FROM people WHERE age With prepared statements you don't stick the values right into the query. For mysqli substitute the variable with a question mark. No quotes, even for strings. Speaking of quotes, don't use quotes for numbers. Prepared statement or not. [code=php:0] if ($query = mysqli_prepare($conn, "SELECT FirstName, LastName, Age, Hometown, Job FROM people WHERE age Quote Link to comment https://forums.phpfreaks.com/topic/259084-php-number-of-variables-error/#findComment-1328244 Share on other sites More sharing options...
whojstall11 Posted March 16, 2012 Author Share Posted March 16, 2012 OMG thank you thanks for the explain too great work Quote Link to comment https://forums.phpfreaks.com/topic/259084-php-number-of-variables-error/#findComment-1328246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.