Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\nick\admin\updatestudent.php on line 55

What I have tried:

PHP
<?php 
session_start();

if(isset($_SESSION['uid']))
{
echo "";  

}
else
{
header('location: ../login.php');

}
?>
<?php
include('header.php'); 
include('titlehead.php');

?>






<table align="center"><tbody><tr><th>Enter Standerd</th><td>
</td><th>Enter Student Name</th><td></td><td colspan="2"></td></tr></tbody></table>


 
<?php
if(isset($_POST['submit']))
{
include('../dbcon.php');

$standerd = $_POST['standerd'];
$name = $_POST['stuname'];

$sql="SELECT * FROM `studentinfo` WHERE `standerd`='$standerd' AND `name` LIKE `%$name%`  ";
$run=mysqli_query($con,$sql);

if(mysqli_num_rows($run)<1)
{

echo "";
}
else
{
$count=0;
while($data=mysqli_fetch_assoc($run))
{
$count++;
?>  
<?php

}
}


}
?>           

<table align="center" width="80%" border="1" style="margin-top: 10px"><tbody><tr style="background-color: #000; color: #fff"><th>No</th><th>Image</th><th>Name</th><th>ROLL NO</th><th>Edit</th></tr><tr><td colspan="5">No Records Found</td></tr><tr><td><?php echo $count; ?></td><td><img scr="../dataimg/<?php echo $data['image']; ?>" style="max-width:100px;"</td><td><?php echo $data['name']; ?></td><td><?php echo $data['rollno']; ?></td><td>Edit</td></tr></tbody></table>
Posted
Updated 13-Apr-18 23:22pm
v2

This is one of the most common MySQL questions asked on this forum. And the cause is that too many programmers do not check the results of function/method calls.

And the answer can easily be found by reading the documentation. If a MySQL command succeeds it returns a mysqli_result object. If it fails it returns a boolean value of false. So before you use the result for the next statement you must check to see if it is the value false.
 
Share this answer
 
PHP
$sql="SELECT * FROM `studentinfo` WHERE `standerd`='$standerd' AND `name` LIKE `%$name%` ";

Not a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900