eljaydee Posted April 12, 2020 Share Posted April 12, 2020 (edited) I have searched the internet about this and found hundreds have asked the question and not once was it answered in a meaningful way--or maybe I'm just dense. Would somebody please tell me what is the problem here: Simple, simple form: <html> <body> <form action="send_post.php" method="post"> <p>A: <input type="text" name="A"> <p>B: <input type="text" name="B"> <p><input type="submit"> </form> </body> </html> =========== Simple, simple PHP script: <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'xyz'; $dbname = 'ABC'; $conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname); if($conn) echo 'Connected successfully. <br> Here are the results of your query:<br><br>'; $A=$_POST["A"]; $B=$_POST["B"]; $sql = 'SELECT * FROM numbers WHERE A = $A AND B = $B'; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_array($result)) { echo $row["0"] . ", "; } } else { echo "0 results"; } mysqli_close($conn); ?> Which is 'parameter 1'? and which is the 'bool given'? But most importantly, how should it be written so that it returns the desired results? I have checked the query from the CMD line, it returns multiple entries. Really, I have reached FRUSTRATION OVERLOAD! Edited April 12, 2020 by eljaydee Quote Link to comment https://forums.phpfreaks.com/topic/310548-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-bool-given/ Share on other sites More sharing options...
benanamen Posted April 12, 2020 Share Posted April 12, 2020 (edited) Your query is failing. You are using single quotes so the variables are not being interpolated. You should be using Prepared Statements anyways. NEVER EVER put variables in the query and don't create variables for nothing. There is no need to manually close the connection. Php will do it automatically. I would also recommend you use PDO. Here is a tutorial to get you going. https://phpdelusions.net/pdo Edited April 12, 2020 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/310548-mysqli_num_rows-expects-parameter-1-to-be-mysqli_result-bool-given/#findComment-1576728 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.