mysqli_num_rows error when uploaded to webserver [duplicate] - php

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));

Related

second mysqli_query() is not returning a result [duplicate]

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 1 year ago.
First mysqli_query is working just fine and is getting a result, but the second one isn't making it past the if condition, it's like $result is returning false.
I saw similar questions but non of them seemed to be the problem I am looking for.
I just want to point out that there is no problem in the sql statement its working fine in the database.
session_start();
$username = $_SESSION['username'];
$id = $_SESSION['id'];
//FIRST SQL QUERY
$sql = "call getrounds($id);";
if($result = mysqli_query($conn, $sql))
{
while($row = mysqli_fetch_assoc($result))
{
if($row['winner'] == "Player"){
$playerstatus="Win";
$botstatus="Lose";
}else if($row['winner'] == "Epsilon"){
$playerstatus="Lose";
$botstatus="Win";
}else{
$playerstatus="Draw";
$botstatus="Draw";
}
echo "<script type=text/javascript>createRow('".$username."','Epsilon',".$row['playerscore'].",".$row['botscore'].",'".$playerstatus."','".$botstatus."');</script>";
}
mysqli_free_result($result);
}
//SECOND SQL QUERY
$sql = "SELECT botwins, playerwins FROM game WHERE id=$id;";
if($result = mysqli_query($conn, $sql))
{
echo "success"; //To test if the $result is not false (its returning false).
while($row = mysqli_fetch_row($result)) //I also tried mysqli_fetch_assoc but it didn't work.
{
if($row[0] >= 10 || $row[1] >= 10){
$sql = "call resetgame($id);";
mysqli_query($conn, $sql);
}
}
mysqli_free_result($result);
}
When I removed the first query and left the second, the second worked just fine.
Why can't I put them together?
I am not getting any errors, but I am not getting any results from the second query either.
Can you try not to reuse the queries variables?
For example:
$result -> $result_2
$sql -> $sql_2
$row -> $row_2

Error in echo when use max() in mysql query [duplicate]

This question already has answers here:
Object of class mysqli_result could not be converted to string
(5 answers)
Closed 1 year ago.
i have to find max value from database. for this purpose i have used max() with where clause but when i echo the result then i get this error.
Catchable fatal error: Object of class mysqli_result could not be converted to string in
i have searched alot and tried this,, this and this and some of others but found nothing helpfull...
my code is :
include('connection.php');
$qry = "SELECT MAX(week) FROM reservation WHERE status= 1" ;
$result = mysqli_query($connection,$qry2);
echo $result ;
on the same page other query is working fine but this one is not..
what i want :
basically i want to get the maximum week number where status is = 1
Hope this helps you
$result = mysqli_query("SELECT MAX(week) AS max_week reservation WHERE status= 1");
$row = mysqli_fetch_array($result);
echo $row["max_week"];
Here is corrected code:
include('connection.php');
$qry = "SELECT MAX(week) as max_week FROM reservation WHERE status= 1" ;
$result = mysqli_query($connection,$qry);
while($row = mysqli_fetch_array($result)) {
echo $row['max_week'];
}

mysqli_fetch_array() error [duplicate]

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'];
}

mysql_num_rows() expects parameter 1 to be resource error at android [duplicate]

This question already has answers here:
mysql_num_rows() expects parameter 1 to be resource, boolean given in [duplicate]
(2 answers)
Closed 7 years ago.
I am trying to send userid and otp which is entered in an edittext in an android app but from server side i get following response.
mysql_num_rows() expects parameter 1 to be resource, boolean given in
/nfs/c07/h02/mnt/111018/domains/surun.co/html/demo/rest/api.php
on line 168
line no 168 from php code
if(mysql_num_rows($results) > 0)
The php code in more details follows:
public function selectQuery($table_name,$fields,$where="",$show = 0)
{
$i =0;
if($where == "")
$sql = "SELECT ".$fields." FROM ".$table_name;
else
$sql = "SELECT ".$fields." FROM ".$table_name." WHERE ".$where;
//MySqli Select Query
if($show == 1)
return $sql;
$results = mysql_query( $sql,$this->db );
if(mysql_num_rows($results) > 0)
{
while($row = mysql_fetch_assoc($results))
{
$result[$i++]= $row;
}
}
return $result;
}
Read this link and apply these changes How could I change this mysql to mysqli? while also adding error checking in the form of
$results = mysqli_query($this->db, $sql) or die (mysqli_error($connection));
(or for MySQL just use $results = mysqli_query($sql,$this->db) or die (mysql_error()); )
What you currently have is that your $this->db value is not connecting the database properly or you have a syntax error in your WHERE clause.

Mysqli num rows and mysqli fetch array issue [duplicate]

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)

Categories