Computing.Net > Forums > Programming > MySQL/PHP query problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

MySQL/PHP query problem

Reply to Message Icon

Name: bryboy2002
Date: April 16, 2005 at 10:35:26 Pacific
OS: Windows XP
CPU/Ram: Athlon AMD/448 RAM
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: Laler
Date: April 16, 2005 at 18:33:35 Pacific
Reply:

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.

---
Site of the Day


0

Response Number 2
Name: Laler
Date: April 16, 2005 at 18:36:56 Pacific
Reply:

$number = mysql_num_rows ($link_id);

should be

$number = mysql_num_rows ($result);

:D

---
Site of the Day


0

Response Number 3
Name: bryboy2002
Date: April 16, 2005 at 19:24:45 Pacific
Reply:

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.


0

Response Number 4
Name: Laler
Date: April 16, 2005 at 20:00:11 Pacific
Reply:

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:

mysql manual
google

---
Site of the Day


0

Response Number 5
Name: Laler
Date: April 16, 2005 at 20:06:50 Pacific
Reply:

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)

---
Site of the Day


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Java Help!! Assigning a value to a co...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: MySQL/PHP query problem

PHP and MYSQL, query wont work www.computing.net/answers/programming/php-and-mysql-query-wont-work/10069.html

A problem in MYSQL & PHP..... www.computing.net/answers/programming/a-problem-in-mysql-amp-php/3124.html

Re mysql/php www.computing.net/answers/programming/re-mysqlphp/8043.html