Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I installed MySQL and PHP for my Apache server. I wanted to make a test php page for retrieving data from the MySQL database. Here is my PHP script:
<html>
<head><title> How to Grab your MySQL Data </title></head>
<body bgcolor="#FFFFFF"><?
/* declare some relevant variables */
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "pass";
$DBName = "info";
$table = "test";$link_id = mysql_connect($DBhost,$DBuser,$DBpass);
if (!link_id){die("Unable to connect to database".mysql_error());}
$sqlquery = "SELECT * FROM $table where opinion = 'Great Job'";
$result = mysql_query($sqlquery);
$number = mysql_numrows($result);$i = 0;
if ($number < 1) {
print "<CENTER>There Were No Results for Your Search in Table '$table'</CENTER>";
}
else {
while ($number > $i) {
$thename = mysql_result($result,$i,"name");
$theemail = mysql_result($result,$i,"email");
print "Name: $thename
E-Mail:
$theemail</p>";
$i++;
}
}
?>
</BODY></HTML>The problem is even though I can connect to the database (I assume this because it doesn't give a connection error), the script always says that their are no results. The MySQL table I am testing ('test') has 2 entries with an opinion of 'Great Job' and so it should be returning those two entries. Instead it finds none. Can you tell me what is going wrong?

hi try this:
$link_id = mysql_connect ($DBhost,$DBuser,$DBpass) or die (mysql_error ());
mysql_select_db ($DBName, $link_id);
$sqlquery = "SELECT * FROM `".$table."` WHERE `opinion` = 'Great Job'";
$result = mysql_query ($sqlquery) or die (mysql_error ());
$number = mysql_num_rows ($link_id);
you didnt select the database, you have a wrong function name, unusual syntax etc... outputting the error can (and should be on development stage) also be done in the mysql_query, I think that's where most error occurs.

Thanks for the help, but it still doesn't work. Luckily, it gave out an error message. Here it is:
Client does not support authentication protocol requested by server; consider upgrading MySQL client
Can you tell me what this means and how to fix it?
Thanks again.

sorry I never had that error so I can't say much. maybe someone will know better. in the mean time you might want to take a look on these links:

btw: I said above that you have a wrong function name. actually, mysql_numrows is not wrong but it's deprecated (might not be available anymore in the future)

![]() |
Java Help!!
|
Assigning a value to a co...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |