Click here to Skip to main content
11,493,391 members (58,730 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP MySQL
Hi! So I'm a super noob beginner in pHp and I'm just doing my best to understand all of this.
I've managed to fix every problem that I've come in contact with except this one.

mysql_num_rows() expects parameter 1 to be resource, boolean given

I get this error from trying to run this

if(isset($_POST['search_name'])) {
    $search_name = $_POST['search_name'];
    if(!empty($search_name)) {
        $query = "SELECT guild, focus, website, leader, members, voip, post, yes_no_website, single_multiple_leadersw FROM guilds WHERE guild LIKE '%".mysql_real_escape_string($search_name)."%'";
 
        $query_run = mysql_query($query);
                if (mysql_num_rows($query_run)>=1) {
                    while ($query_row = mysql_fetch_assoc($query_run))  {
                        echo $query_row['guild'];
                    }
 

                 }else{
                echo 'No results found.';
            }
        }
}

And I have no idea how to fix this, I apologize if I didn't post in the correct format or something.

Thanks for any help
Posted 31-Mar-13 16:45pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

According to documentation,for SELECT and other statements returning resultset, mysql_query()[^] returns a resource on success, or FALSE on error. Check your query in console or any MySQL gui tool.
Place breakpoint (if you are using some intelligent IDE) or var_dump($query_run) after mysql_query($query) and you will see, what the function call returned.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 419
1 Maciej Los 286
2 F-ES Sitecore 224
3 KarstenK 210
4 CPallini 208
0 Sergey Alexandrovich Kryukov 10,132
1 OriginalGriff 8,630
2 Sascha Lefèvre 3,624
3 Maciej Los 3,392
4 Richard Deeming 2,500


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 31 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100