MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 17th, 2004, 10:16 AM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql_num_rows(): supplied argument is not a valid MySQL result resource in

Could someone here offer me some hint what is wrong with mysql_num_rows():

<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
// create short variable names
$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}

$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_connect("localhost","","");
if (!$db)
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
mysql_select_db('books');
$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 <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}
?>
</body>
</html>

Reply With Quote
  #2  
Old March 17th, 2004, 11:26 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 14
Generally your error means your query didn't execute

I recommend adding an or die() line to your line $result = mysql_query($query);

Thus, the line might read:
$result = mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query");

Reply With Quote
  #3  
Old March 18th, 2004, 07:01 AM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
mysql_num_rows(): supplied argument is not a valid MySQL result resource in

MadCow: After the changes above, I got the following error msg now:

No Database Selected
Couldn't execute query: select * from books where author like '%Michael%'

Would appreciate your kind assistance.

Reply With Quote
  #4  
Old March 18th, 2004, 10:24 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
you did not connect to a database so you cant query anything

you need to do this before you query

PHP Code:
 $db_connect=mysql_connect("localhost/where ip to connect to","username","password") or die ("Could not connect to database");
mysql_select_db("your database") or die ("Could not select database!"); 

Reply With Quote
  #5  
Old March 18th, 2004, 11:35 AM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Could not select database!

Bruski: I have changed the line u mentioned above but it's giving me this error msg:

Could not select database!

$db_connect=mysql_connect("localhost","","") or die ("Could not connect to database");
mysql_select_db("books") or die ("Could not select database!");


$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query");

$row = mysql_fetch_array($result);
$num_results = mysql_num_rows($result);
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i <$num_results; $i++)
{

echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}

Reply With Quote
  #6  
Old March 18th, 2004, 03:12 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 14
have you created a database on your mysql?

make sure the database "books" exists...
I recommend connecting to MYSQL manually (via command line)

Reply With Quote
  #7  
Old March 18th, 2004, 03:58 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via ICQ to dhouston
Looks like you need to provide a username and password. Additionally, doesn't mysql_query() usually take a resource as the second parameter? Check the docs, and if there's a second parameter, pass $db_connect.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #8  
Old March 18th, 2004, 07:54 PM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Database

MadCowDzz: I managed to retrieve the MySQL db (books) in a command line.

dhouston: Mind enlighten me what u mean by second parameter?

The problem still persist.

Any help would be appreciated.

Reply With Quote
  #9  
Old March 19th, 2004, 07:24 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via ICQ to dhouston
Read the function documentation at php.net. You can pass a second item to the function call (inside the parentheses). I'm proposing that the function may need your database resource passed explicitly in order to work.

Reply With Quote
  #10  
Old March 19th, 2004, 10:52 AM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Access denied for user: ''@'localhost' to database 'books'

I have made some changes to the codes and now getting this error msg:
Access denied for user: ''@'localhost' to database 'books'

However, I could access the "books" db in the mysql command prompt using "root" login.
Code:
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
// create short variable names
$searchtype=$HTTP_POST_VARS['searchtype'];
$searchterm=$HTTP_POST_VARS['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
	 echo 'You have not entered search details. Please go back and try again.';
	 exit;
}
 
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
 
$my_connection = @mysql_connect('localhost', '', '');
// the "@" is used to supress the generic function error.
if (!$my_connection) { // if value in variable is false (!)
	die('Could not connect to MySQL database server, the server returned the error: '.mysql_error());
}
$db = @mysql_select_db('books');
if (!$db) { // if value in variable is false (!)
	die('Could not select MySQL database, the server returned the error: '.mysql_error());
}
// Now we can do a query
$query = mysql_query('select * from books where ".$searchtype." like '%".$searchterm."%'');
$result = mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query");
 
$row = mysql_fetch_array($result);
$num_results = mysql_num_rows($result);
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i <$num_results; $i++)
{
 
	 echo '<p><strong>'.($i+1).'. Title: ';
	 echo htmlspecialchars(stripslashes($row['title']));
	 echo '</strong><br />Author: ';
	 echo stripslashes($row['author']);
	 echo '<br />ISBN: ';
	 echo stripslashes($row['isbn']);
	 echo '<br />Price: ';
	 echo stripslashes($row['price']);
	 echo '</p>';
}
?>
</body>
</html>

Reply With Quote
  #11  
Old March 19th, 2004, 11:02 AM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Client does not support authentication protocol requested by server; consider upgradi

When I changed the connection string to my "root" password, I am getting this error msg:

Client does not support authentication protocol requested by server; consider upgrading MySQL client

$my_connection = @mysql_connect('localhost', 'root', 'password1');
// the "@" is used to supress the generic function error.
if (!$my_connection) { // if value in variable is false (!)
die('Could not connect to MySQL database server, the server returned the error: '.mysql_error());
}


Hope someone here could offer me some hints

Reply With Quote
  #12  
Old March 19th, 2004, 01:54 PM
richardtham richardtham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 9 richardtham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Talking Case Solved !!

Hi guys,

Finally,fully solved the problem here.

It has something to do with MySQL 4.1 uses an authentication protocal based on a password hashing algorithm that is incompatible with that used by older clients.

Details here: http://www.mysql.com/doc/en/Old_client.html

Thanks to all guys who have contributed. I appreciate it !!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > mysql_num_rows(): supplied argument is not a valid MySQL result resource in


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap