0

I have a piece of PHP code I am using to grab the 20 next messages in a database.

<?php
    $user_email_msg = "bob@gmail.com";
    $msg_email = "sam@gmail.com";
    $start_query_msg = 1;
    $end_query_msg = $start_query_msg-20;
    $user_link_msg = mysqli_connect("localhost", "root", "admin", $user_email_msg);
    $query_msg = "SELECT * FROM " . $msg_email . " WHERE id BETWEEN " . (string)$end_query_msg . " AND " . (string)$start_query_msg;
    $result_msg = mysqli_query($user_link_msg, $query_msg);

    $row_msg = mysqli_fetch_all($result_msg, MYSQLI_NUM);

    $next_20 = $row_msg[0];

    print_r($next_20);
?>

When I run this code I get this error message:

"Warning: mysqli_fetch_all() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\jayden\messages.php on line 10"

I am so lost here, because I can't see any way that $result_msg can be returning a boolean value.

How can I fix the issue?

Dharman
  • 30,962
  • 25
  • 85
  • 135
user2696287
  • 335
  • 1
  • 4
  • 10
  • Print the query and execute it manually using phpMyAdmin or your MySQL command prompt. If it works, use `mysqli_error()` to know what exactly is going wrong. If not, fix your query. – Amal Murali Jun 05 '14 at 05:31

3 Answers3

2

I may be wrong, but most likely your fourth parameter to mysqli_connect is not an email address but should rather be the database name

SomeoneYouDontKnow
  • 1,289
  • 10
  • 15
0

echo the variable $query_msg and run the query in phpmyadmin or any favorite application. The error is about mistake in sql query check that now.

gvgvgvijayan
  • 1,851
  • 18
  • 34
0

print the query and check if the query is ok.

print_r($query_msg);

this problem occurs when your query is not right.

Rokib
  • 46
  • 2