#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0

    Exclamation Why mysql_num_rows doesn't work?? Please help


    I created a forum-like app in php and uploded to my 1&1 windows host, everything works well but when i use a mysql_num_rows() it says in the hmlt code (displayed in the normal page) this
    PHP Code:
    Warningmysql_num_rows() expects parameter 1 to be resourceboolean given in E:\kunden\homepages\3.... 
    ecc. ecc. Why?
  2. #2
  3. Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,688
    Rep Power
    1842
    That'd be down to an inavlid usage of the function. Care to show what came before (basically the code involved in the doing the previous select).
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,473
    Rep Power
    653
    You are using the deprecated (for more than a decade) MySQL extensions. Switch to PDO and prepared statements then come back if you are still having problems. Your code is invariably open to injection attack.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2011
    Location
    Sydney Australia
    Posts
    215
    Rep Power
    88
    Originally Posted by Enryzz
    Why?
    Because the query you used failed and returned FALSE rather than a result set.
    You'll need to fix the sql you send to MySQL.
    And get rid of the old deprecated mysql_ stuff.Use PDO or mysqli_ instead.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0
    Sorry can you give me the link to a good tut about mysqli or pdo please. Just creating this web app took me about 1 month so i cant just change everything.
    Another thing, why it worked well in Mamp on mac)(in localhost:888/...)?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,082
    Rep Power
    381
    maybe you have data in your local server *mysql*

    Comments on this post

    • Enryzz disagrees
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0
    sorry i don't understand
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,473
    Rep Power
    653
    Read Jacques1's article. Also read his article on security.

    Comments on this post

    • Enryzz agrees
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0
    ok learned how to use pdo and mysql but i still need to know how to fix thi problem with mysql_num_rows()! thank you
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,473
    Rep Power
    653
    You will be using a different set of functions with PDO so solving this one is pointless.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,082
    Rep Power
    381
    your mysql query, does it run in MySQL? phpMyadmin or similar? try that.. echo query in the browser and run that through phpmyadmin and see if it works, could be some mistake...

    also if you have data in your local wamp mysql and not production, then it will return false, i was only giving a suggestion because you havent provided us with enough useful code like asked before i believe.
    this might be why result is returning FALSE...
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0
    Sorry, you are right i'll provide more code but now i cant.
    Sorry if i make some mistakes but i'm italian and 14 years old
  24. #13
  25. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,884
    Rep Power
    6356
    The error you were getting indicates that you attempted to call mysql_num_rows($something), but you expected $something to be a valid mysql result set. Instead, $something was FALSE. That means that whatever created $something (likely mysql_query) is incorrect or failing. It could have worked on your mac because you had a different database server configuration, different character set collation, or any number of other things.

    What you need to do right now to get this working is:
    1) Find that mysql_num_rows call
    2) Find what is inside the parens ($something)
    3) Go UP from there to find out where that thing from #2 was created
    4) Right after that line, insert error handling in the form of:
    PHP Code:
    if ( $something === false ) { echo "MySQL error! " mysql_error() . "<br />\n"; } 
    The error that gets printed will show up on your screen, and if you can't fix it yourself from that information you can post it here (or in a new thread in the MySQL forum) and we'll tell you what the next steps are. This kind of error checking I mention is not good practice in a production or professional environment, but while you're learning simply dumping the errors to the screen is fine. If you were to sell this software or turn it into a portfolio item, you should remove the line I gave you and replace it with real error handling.

    Long-term, you need to rewrite this code to use more modern methods of interacting with a database, but again for the time being while you're learning, you can get over this roadblock to continue your education, as long as you realize that your methods of interacting with the database are wrong. The syntax of the queries remains relatively unchanged, it's just the actual php functions you're using that are incorrect.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2014
    Posts
    24
    Rep Power
    0
    thank you ManiacDan your reply was perfect!!!
    I'll try to do what you said and i'll let you know. THANK YOU

IMN logo majestic logo threadwatch logo seochat tools logo