This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 2 years ago.
<?php
$con = mysqli_connect('localhost','root','','db') or die('Error connecting to MySQL server.');
if(isset($_POST['rollNo'])){
$rollNo = $_POST['rollNo'];
$query = "Select * from table where ROLL_NUMBER LIKE '$rollNo'";
$select = mysqli_query($con, $query);
printf(mysqli_query($con));
while ($row = mysqli_fetch_array($select)) {
echo $row['FIRST_NAME'];
}
}
?>
It is showing the error that
mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given.
Use below code segment
while($row = mysqli_fetch_assoc($result))
{
echo $row['FIRST_NAME'];
}
Related
This question already has answers here:
Object of class mysqli_result could not be converted to string
(5 answers)
Closed 1 year ago.
I'm having some issues with my SQL Query. I am trying to run an sql query that saves the output into a variable and then print the variable in a different section of code:
Query:
$sql = "select Count(distinct `Customer Name`) as columnNameCount from allservers";
$result = mysqli_query($DBcon, $sql);
Display variable:
<h3 align="center"><?php echo $resultarr;?></h3>
Error message:
Catchable fatal error: Object of class mysqli_result could not be converted to string
<?php
$sql = "select Count(distinct `Customer Name`) as columnNameCount from allservers";
$result = mysqli_query($DBcon, $sql);
$row = mysqli_fetch_row($result);
?>
<h3 align="center"><?php echo $row[0];?></h3>
Remember: Mysqli_query() return an Object Resourse to your variable $result! Not a String!
You can't directly use it as $result variable!
If you have multiple results, you can loop:
while ($row = $result->fetch_assoc())
echo $row['some_row'];
else you have to fetch as row and display according to index:
$row = $result->fetch_row();
echo $row[0]; // $row[index]
Read The Documentaion
This question already has answers here:
mysqli_num_rows() expects parameter 1 to be mysqli_result, object [duplicate]
(3 answers)
Closed 8 years ago.
Hello I am trying to look after content of Selected query... but however the error appears:
mysqli_num_rows() expects parameter 1 to be mysqli_result ...
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysql_error());
$result = $stmt->execute();
// check for empty result
if (mysqli_num_rows($result) > 0) {
..
}
EDIT
NEW ERROR mysqli_fetch_array() expects parameter 1 to be mysqli_result, object given in...
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysqli_error());
$stmt->execute();
$stmt->store_result();
// check for empty result
if ($stmt->num_rows > 0) {
// looping through all results
$response["array"] = array();
while ($row = mysqli_fetch_array($stmt)) {
... }
I think I got it:
while ($row = $stmt->fetchAll()) {
// temp user array
$array= array();
$array["bla"] = $row["bla"];
... }
but I get only "null" as value...?
EDIT
Now i got it:
$stmt->bind_result($column1, $column2...)
then
$array["bla"] = $column1;
$array["bla2"] = $column2;
but isn't it possible to bind_result all colums without to put every single one into a variable?
or isnt it possible to use this :
$array["bla"] = $row["bla"];
so it puts the value from the row with the column "bla" into $array[bla]?
because the way i solved it, seems to be veyr difficult
Correct is
$stmt= $this->conn->prepare("SELECT * FROM table") or die(mysql_error());
$result = $stmt->execute();
$result->store_result();
// check for empty result
if ($result->num_rows > 0) {
..
}
This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 2 years ago.
I try to google it but, i really dont understand what is the problem with this query. Here is code
include_once("includes/db_connection.php");
//Upit za prikaz pitanja!
$listaPitanja = "";
$sql = "SELECT id, username, question FROM useroptions ORDER BY DESC";
$user_query = mysqli_query($db_connection, $sql);
$pitanjaCount = mysqli_num_rows($user_query); //line 8
if ($pitanjaCount > 0) {
while ($row = mysqli_fetch_array($sql)) { //line 10
$id = $row['id'];
$question = $row['question'];
$username = $row['username'];
$listaPitanja .= '<div id="brojOdgovora">'.$id.'</div>
<div id="tekstPitanja"><h3>'.$question.'</h3></div>
<div id="userPitanja"><h6>'.$username.'</h6></div>';
}
} else {
$listaPitanja = "There is no inserted questions!";
}
This query gives me nothing. Just this error mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in something on line 8, and if i delete ORDER BY DESC there is some error on line 10?
Sorry if it repeated, but i have no idea to solve this!! Thank you!
Your SQL statement has no ORDER column:
$sql = "SELECT id, username, question FROM useroptions ORDER BY DESC";
Change it with the correct column name:
$sql = "SELECT id, username, question FROM useroptions ORDER BY column_name DESC";
Probably, mysqli_query is returning false instead of mysqli_result object.
To add segarci,
$row = mysqli_fetch_array($sql)
should be
$row = mysqli_fetch_array($user_query)
This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 9 years ago.
I am getting the errors:
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in /home/www/thetotempole.ca/phpimageupload/pagecounter.php on line 19
title bodytext
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in /home/www/thetotempole.ca/phpimageupload/pagecounter.php on line 32
when I try to run my PHP page. I am expecting this problem is originating from either the $sql or the $connection. I don't believe it is my $connection because all of my variables are correct and I am not getting a connection error. The code is supposed to display my MySQL table's data four rows per page. After four rows have been displayed it will create a new page for the next four rows, and so on.
Here is my full PHP page's code:
<?php
if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
$dbhost = 'ddm';
$dbuser = 'kdm';
$dbpass = 'Kder';
$dbname = 'kegbm';
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
if(! $connection )
{
die('Could not connect: ' . mysqli_error());
}
$start_from = ($page-1) * 4;
$sql = 'SELECT * FROM `testdb` ORDER BY `created` ASC LIMIT "'.$start_from.'",4';
$rs_result = mysqli_query ($connection, $sql);
echo mysqli_error( $connection );
?>
<table>
<tr><td>title</td><td>bodytext</td></tr>
<?php
while ($row = mysqli_fetch_assoc($rs_result)) {
?>
<tr>
<td><? echo $row["title"]; ?></td>
<td><? echo $row["bodytext"]; ?></td>
</tr>
<?php
};
?>
</table>
<?php
$sql = "SELECT COUNT(`created`) FROM `testdb`";
$rs_result = mysqli_query($connection, $sql);
$row = mysqli_fetch_row($rs_result);
$total_records = $row[0];
$total_pages = ceil($total_records / 4);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";
};
?>
it's your solution :
$sql = "SELECT * FROM `testdb` ORDER BY `created` ASC LIMIT $start_from,4";
note:
in your code : before and after of $start_from has " that dont must !
The documentation states
Returns FALSE on failure. For successful SELECT, SHOW, DESCRIBE or
EXPLAIN queries mysqli_query() will return a mysqli_result object. For other
successful queries mysqli_query() will return TRUE.
So your query is most likely failing for some reason. Find out what the raw SQL is, and you will probably be able to spot your error.
This question already has an answer here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(1 answer)
Closed 9 years ago.
I have the following piece of code:
$query = "SELECT * FROM delegations where EMail='". $_REQUEST["user"] ."' AND Password = '". Encrypt($_REQUEST["pass"]) ."' ";
$results = mysqli_query($con, $query);
if(mysqli_num_rows($results) > 0) {
while($row = mysqli_fetch_array($results)) {
$_SESSION["login"] = $row["ID"];
echo "Welcome <b>" . $row["FirstName"] . "</b>! You have logged in succesfully! Click here to continue!";
}
Which runs fine when I run it on my localhost xampp. However, when I upload it to my web-server I get the following error code:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result,
boolean given in *path*/login.php on line 28
Any suggestions?
$results = mysqli_query($con, $query) or die(mysqli_error( $con ));
I think $results should be false; Using mysqli_error you can track this.
otherwise check
var_dump($results);
Your mysqli_query is failing, please add a error handler to display the error.
$results = mysqli_query($con, $query) or die(mysqli_error($con));