Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
I wrote this code to show data from data base in my webpage
this is my code:
PHP
@ $db=mysql_pconnect('localhost','bookshop');
        if (!$db)
        {
            echo 'Error: coud not connect to database. please try again later.';
            exit;
        }
        mysql_select_db('bookshop');
        $query="select * from books where ".$searchtype." like '%".$searchterm."%'";
        $result=mysql_query($query);
        $num_results=mysql_num_rows($result);
        echo '<p>Number of books found: '.$num_results.'</p>';
        for ($i=0;$i<1;$i++)
        {
            $row=mysql_fetch_array($result);
            echo '<p><strong>'.($i+1).'.title: ';
            echo htmlspecialchars(stripslashes($row['title']));
            }

but I had this erors
VB
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\chapter1\resultpage.php on line 35
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\xampp\htdocs\chapter1\resultpage.php on line 39

what can I do with this problem
I checked result with mysql_eror() function and I saw this message: No database selected how I can select the database
Posted
Updated 27-Jun-11 2:06am
v2

mysql_query() returns FALSE if there's an error in the query. You must check the $result before passing it to mysql_num_rows() or mysql_fetch_array().
 
Share this answer
 
Comments
sadegh_sh 27-Jun-11 7:59am    
Hi thanks for your help I checked result and I realized that no database connected but I have this database in my php admin how I can select my database
Do a <a href="http://php.net/manual/en/function.mysql-fetch-array.php">mysql_fetch_array</a>[<a href="http://php.net/manual/en/function.mysql-fetch-array.php" target="_blank" title="New Window">^</a>] on $result.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900