hey guys, so im trying to display data from my database into a table but i got this error :

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\CashFlow\balance_report.php on line 45

code:

<?php
require "connect.php";

if($_SESSION['name'])
{
    $name = $_SESSION['name'];
    $query=("SELECT * FROM asset WHERE name = $name");
    $result=mysql_query($query);
    $num=mysql_num_rows($result);
    mysql_close();


    echo "<b><center>Asset</center></b></br>";

    $i=0;;while($i<$num)
    {
        $house=mysql_result($result,$i,"house");
        $vehicle=mysql_result($result,$i,"vehicle");
        $current=mysql_result($result,$i,"current");
        $savings=mysql_result($result,$i,"savings");
        $kwsp=mysql_result($result,$i,"kwsp");
        $haji=mysql_result($result,$i,"haji");
        $asb=mysql_result($result,$i,"asb");
        $stock=mysql_result($result,$i,"stock");
        $property=mysql_result($result,$i,"property");
        $others=mysql_result($result,$i,"others");
        $total=mysql_result($result,$i,"total");

        echo "<table border='1'>
              <tr>
                <td><b>Personal</b></td>
            </tr>
            <tr>
                <td>House : $house</td>
            </tr>
            <tr>
                <td>Vehicle <dfn>(Car,Motorcycle etc)</dfn> : $vehicle</td>
            </tr>
            <tr>
                <td><b>Cash</b></td>
            </tr>
            <tr>
                <td>Current Account : $current</td>
            </tr>
            <tr>
                <td>Savings Account : $savings</td>
            </tr>
            <tr>
                <td><b>Investments</b></td>
            </tr>
            <tr>
                <td>KWSP : $kwsp</td>
            </tr>
            <tr>
                <td>Tabung Haji : $haji</td>
            </tr>
            <tr>
                <td>ASB : $asb</td>
            </tr>
            <tr>
                <td><b>Stock : $stock</b></td>
            </tr>
            <tr>
                <td><b>Property : $property</b></td>
            </tr>
            <tr>
                <td><b>Others</b> : $others</td>
            </tr>
            <tr>
                <td><b>Total</b> : $total</td>
            </tr>

              </table>",$i++;
    }
}
?>

what am i doing wrong?

You must use single quote around $name

"SELECT * FROM asset WHERE name = '$name'"

You shouldn't use mysql_* functions, since they are deprecated. Use mysqli_* or mysql_pdo.

The problem is likely with your query. Have you tried the query manually to see what the results are?

I agree with JorgeM, use mysqli or PDO.

With this though, you should be checking for errors as well.

$result=mysql_query($query) or die (mysql_error());

thanks urtrivedi. i added the single quotes and it executed perfectly. jorgeM i'll try mysqli in the future. thanks for the input guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.