Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP query

  • 09-03-2013 11:06pm
    #1
    Posts: 0


    trying to build a cart and i'm getting this error

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



    <?php

    session_start();

    $page = 'index_one.php';

    mysql_connect('localhost','root','root') or die(mysql_error());
    mysql_select_db('cart') or die(mysql_error());

    function products() {

    $get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER By id DESC');
    if (mysql_num_rows($get)==1) {
    echo "There are no products to display!";
    }
    else {




    }


    }




    ?>



    can any one spot were I'm going wrong thanks,


Comments

  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    trying to build a cart and i'm getting this error

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



    <?php

    session_start();

    $page = 'index_one.php';

    mysql_connect('localhost','root','root') or die(mysql_error());
    mysql_select_db('cart') or die(mysql_error());

    function products() {

    $get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER By id DESC');
    if (mysql_num_rows($get)==1) {
    echo "There are no products to display!";
    }
    else {




    }


    }




    ?>



    can any one spot were I'm going wrong thanks,

    Whats the result when you run the query manually.

    When query fails, it returns FALSE, hence the BOOLEAN you are passing to mysql_num_rows(); You should always check if a result actually exists before going on with your code.


  • Posts: 0 [Deleted User]


    yes Chrome, thats the result


  • Registered Users, Registered Users 2 Posts: 2,021 ✭✭✭ChRoMe


    yes Chrome, thats the result

    Eh... wut?


  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    What Chrome is suggesting is that you take your SQL query and try it outside of your php code. Usually in a mysql console or something like phpMyAdmin.
    It's a simple way of testing the validity of your query, isolating that part from the rest of your script. You're seeing an error with mysql_num_rows() because it relies on the (success) return value of mysql_query(). The most likely cause of mysql_query() failing at this point is that your query is bad. Your query could be trying to access columns that don't exist or are misspelled.


  • Posts: 0 [Deleted User]


    Sorry Chrome this is the result I get

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


  • Advertisement
  • Posts: 0 [Deleted User]


    Thanks Donkey Style


  • Closed Accounts Posts: 27,857 ✭✭✭✭Dave!


    Your query is failing, so mysql_query() is returning false, hence the boolean error. As mentioned, try your query in a SQL client or on the CL.


Advertisement