0

I'm new here (in PHP too :D) and I'm trying to install a lottery script but get this error:

Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in /home/u289308161/public_html/lottery/get_lottery.php on line 7 Table 'u289308161_lot.lottery' doesn't exist

u289308161_lot is the database name and the user that uses it.

The get_lottery.php file is:

    <?php
require 'connect.php';

$query="SELECT * FROM lottery ORDER BY lottery_id DESC LIMIT 10";
$result=mysql_query($query);

$num=mysql_numrows($result);

?>

Please help!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3077703
  • 13
  • 1
  • 2
  • 4
  • See [this answer](http://stackoverflow.com/a/11674313/250259) for how to troubleshoot this. – John Conde Dec 07 '13 at 14:34
  • Well, you read the whole error… so does `lottery` exist or not? (It doesn’t, but where *does* it exist?) – Ry- Dec 07 '13 at 14:46

1 Answers1

1

This means that num_rows() can't give a result back because the query is failing. You always need to know if a query is failing:

<?php
require 'connect.php';

$query  = "SELECT * FROM lottery ORDER BY lottery_id DESC LIMIT 10";
$result =mysql_query($query);

if($result == false)
{
    echo 'The query failed.';
    exit();
}

$num = mysql_num_rows($result);

?>
RezaM
  • 167
  • 1
  • 1
  • 11