PHP errors on live server - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, September 25, 2022

PHP errors on live server

I am creating a dynamic website using with a database backend connected to the front end using php. When i run this php code on my local wamp server it runs fine:

<?php
  $servername='xxxxxxxx';
  $dbname='xxxxxx';
  $username='xxxxxx';
  $password="xxxxxxx";

  //create connection
  $conn=new mysqli($servername,$username,$password,$dbname);

  //check connection
  if($conn->connect_error){
      die('Connection failed'.$conn->connect_error);
  }
  if(!isset($_GET['page'])){
    $page=1;
}
else{
    $page=$_GET['page'];
}
$result_per_page=9;
$page_first_result=($page-1)*$result_per_page;
//get total number of pages
$query='SELECT gamename,main_image FROM game_info';
$result=mysqli_query($conn,$query);
$number_of_results=mysqli_num_rows($result);
//total number of pages available
$number_of_pages=ceil($number_of_results/$result_per_page);
//retrieve data and display
$query="SELECT gamename,main_image FROM game_info ORDER BY id DESC LIMIT ". $page_first_result .','. $result_per_page;
$result=mysqli_query($conn,$query);
//display results on webpage
$counter=0;
while($row=mysqli_fetch_array($result)){
    echo'<div id="gamecontainer">
    <div id="imagecontainer">
        <a href="download.php?val='.$row["gamename"].'"><img src="'.$row["main_image"].'"></a>
    </div>
    <div id="title">
        <h3>'.$row["gamename"].'</h3>
    </div>
    <div id="download">
        <a href="download.php?val='.$row["gamename"].'"><button id="downloadbtn">Download</button></a>
    </div>  
</div>';
}
?>

but when i transfer my php file to a live nginx server i get errors on line$result=mysqli_query($conn,$query); saying Warning : mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given and linewhile($row=mysqli_fetch_array($result)) saying : mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in.

What could be the cause of this cause it runs fine on my wampserver but errors on a live one that runs on nginx



source https://stackoverflow.com/questions/73839705/php-errors-on-live-server

No comments:

Post a Comment