-2

Warning: mysqli_fetch_object() expects parameter 1 to be mysqli_result, boolean given in /public_html/header.php on line 35

In the header.php, Connect to database:

$connect=mysqli_connect("localhost","$db_name","$password")
$sql_logo="SELECT * FROM `logo`";
$query_logo=mysqli_query($connect,$sql_logo);

On line 35:

<?php 
   while($result=mysqli_fetch_object($query_logo)){
?>
   <a href="/"><img src="res/img/<?php echo $result->logo_img?>"></a>
<?php } ?>

in my database: the table name is logo and the column name is logo_img.

I don't know what happens, because when I try in XAMPP it's work using that's code.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sofyan
  • 399
  • 4
  • 13
  • Check the return value from `$query_logo`. If it's false - as it almost certainly is - check `mysqli_error($connect)` to see why your query failed. – andrewsi Feb 21 '16 at 21:25
  • you didn't select a db and didn't close off `("localhost","$db_name","$password")` < missing `;` – Funk Forty Niner Feb 21 '16 at 21:27
  • thanks, the error is not select db. i have try `$mysqli_connect("localhost","$user","$db_name","$password")` but i wrong to put the `db_name`, i must put `db_name` after `password` not before it. – Sofyan Feb 21 '16 at 21:36
  • @MuhamadSofyan the parameters order is wrong as stated in my answer below. – Funk Forty Niner Feb 21 '16 at 21:36
  • 1
    @deceze the question you used as a dupe source is related to obsoleted extension while answers there promote outdated and harmful practices. Please consider using the answer I wrote for the purpose instead: [mysqli_fetch_assoc() expects parameter / Call to a member function bind_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param/22662582#22662582) – Your Common Sense Sep 13 '19 at 11:44

3 Answers3

1

This $connect=mysqli_connect("localhost","$db_name","$password")

2 things here.

The $db_name, that must be the last parameter and you've a missing closing semi-colon.

The syntax is:

  • host
  • username
  • password (if any)
  • database

As per the manual

$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");

Make sure you also did properly assign those variables.

If there's no password, you still need the parameter for it, but as empty.

I.e.:

$link = mysqli_connect("127.0.0.1", "my_user", "", "my_db");
                                                ^ that is for the password parameter

Check for errors also:

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • yeah i wrong put `db_name`, i put it before `password` so i find that's error, because the `db_name` must put after `password`. – Sofyan Feb 21 '16 at 21:38
0

Your $query_logo is probably FALSE instead of the results you're trying to fetch. This could mean either your mysqli_connectfails, or the $sql_logo query fails.

Print the errors out using echo mysqli_error($connect) and you will find your answer there.

Also, I'd recommend having a look at object oriented mysqli, looks like you're still figuring stuff out, don't get used to procedural or you'll regret it later.

Cârnăciov
  • 1,169
  • 1
  • 12
  • 24
-2

Please refer the PHP-Manual http://php.net/manual/en/function.mysqli-connect.php for getting the better idea of mysqli syntax.

And for displaying records try to use syntax and code given below:

$conn = mysqli_connect("127.0.0.1", "db_username", "db_password", "Database_anme");
$limit = 10; //$_POST['limit'];
$start   = 0; //$_POST['start'];
$r = mysqli_query($conn, "SELECT * FROM `TABLE_NAME` DESC LIMIT $start,$limit");
while($quotos = mysqli_fetch_object($r)){
    // Your code goes here
}
Mahek Manvar
  • 113
  • 5