473,382 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

MySQL PHP problems

Hi everyone. I've only really just started using php and I've been
trying to use it in conjunction with mysql. I keep getting an error
though when trying to access the result set returned by performing a
query on the database. I've performed queries on the database outwith
php, and it correctly returned the correct details. Here's the code for
it:

<?php
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("ababoc_filmlistings");

$sql = 'SELECT DISTINCT title FROM Listing';
$rs = mysql_query($sql);

$row = mysql_fetch_row($rs); // line 24
echo $row[0];

?>

but I end up with the error:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL
result resource in /home/ababoc/public_html/test/index.php on line 24

I'm really not sure what I could be doing wrong here. Any help would be
much appreciated.

Mar 7 '06 #1
6 1173
In article <11**********************@j52g2000cwj.googlegroups .com>,
dp****@gmail.com (Ababo) wrote:
<?php
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("ababoc_filmlistings");

$sql = 'SELECT DISTINCT title FROM Listing';
$rs = mysql_query($sql);

$row = mysql_fetch_row($rs); // line 24
echo $row[0];

?>

but I end up with the error:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL
result resource in /home/ababoc/public_html/test/index.php on line 24


If $rs isn't a valid result it implies that something went wrong in
creating it. Either in selecting the database or in running the query.
Look at the mysql_error() after each of those.

--
To reply email rafe, at the address cix co uk
Mar 7 '06 #2
Ababo wrote:
Hi everyone. I've only really just started using php and I've been
trying to use it in conjunction with mysql. I keep getting an error
though when trying to access the result set returned by performing a
query on the database. I've performed queries on the database outwith
php, and it correctly returned the correct details. Here's the code for
it:

<?php
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("ababoc_filmlistings");

$sql = 'SELECT DISTINCT title FROM Listing';
$rs = mysql_query($sql);

$row = mysql_fetch_row($rs); // line 24
echo $row[0];

?>

but I end up with the error:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL
result resource in /home/ababoc/public_html/test/index.php on line 24

I'm really not sure what I could be doing wrong here. Any help would be
much appreciated.


Your query most likely threw an error invalidating the result set.

Try this:

$rs = mysql_query($sql);
if( mysql_num_rows($rs) == 0 ) {
echo mysql_error($dbh);
}

and see what you get.

-david-

Mar 7 '06 #3
Ababo wrote:
Hi everyone. I've only really just started using php and I've been
trying to use it in conjunction with mysql. I keep getting an error
though when trying to access the result set returned by performing a
query on the database. I've performed queries on the database outwith
php, and it correctly returned the correct details. Here's the code for
it:

<?php
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I
cannot connect to the database because: ' . mysql_error());
mysql_select_db ("ababoc_filmlistings");

$sql = 'SELECT DISTINCT title FROM Listing';
$rs = mysql_query($sql);

$row = mysql_fetch_row($rs); // line 24
echo $row[0];

?>

but I end up with the error:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL
result resource in /home/ababoc/public_html/test/index.php on line 24

I'm really not sure what I could be doing wrong here. Any help would be
much appreciated.


Check the results of your mysql_select_db() and mysql_query() calls and
see why one failed.

You should *always* check the results of any call to MySQL and handle
errors appropriately!

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 7 '06 #4
Are you absolutely sure that this query is correct? Try putting:
echo mysql_error();

directly after the mysql_query(). It should be more informative.

Mar 7 '06 #5
Ahh, okeydoke. I didn't realise there was a mysql_error() function I
could use. Unfortunately my FTP server has decided to act up (always at
the most inopportune of times), but I shall give it a go once it's up
and running again. :)

Mar 7 '06 #6
Aha! I found out what it was. Turned out that I hadn't given the user
that I was trying to connect with any access privileges to the
database. :-s Whoops! It always turns out to be something stupid.
Thanks for the help though! :)

Mar 7 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary...
0
by: Stefan Hinz | last post by:
Degan, jumping in to try and solve some problems that look pretty obvious to me ... > #options for default service (mysqld2) > (mysqld2) It should be , not (mysqld2).
0
by: Anil Garg | last post by:
Hi, I am trying to install myql on redhat. mysql package used: mysql-3.23.52-unknown-freebsdelf4.6-i386.tar.gz While following the instructions in install document..when i run the follwing...
14
by: Jim Sabatke | last post by:
When I installed MySQL (SuSE 9.0) and first started it, it told me that I needed to set a password for machine.domain.name. I tried following the directions, but it would only setup a password...
3
by: Kirk Soodhalter | last post by:
Hi, This started as a phpmyadmin problem, but has somehow morphed into a mysql problem. I don't know how to fix it. I am posting the conversation from a php newsgroup since it started there. ...
1
by: Alex Hunsley | last post by:
I am trying to install the DBD::mysql perl module. However, it claims I need mysql.h: cpan> install DBD::mysql CPAN: Storable loaded ok Going to read /home/alex/.cpan/Metadata Database was...
2
by: pc | last post by:
hi everyone, we have a server on which someone blew away the MySQL 4 progs directory before installing MySQL 5. When installing MySQL 5 the installation failed with an error stating that it was...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
by: Frances | last post by:
a few days ago I installed XAMPP in my Windows 2000 machine, it completely messed my existing MySQL installation.. I've had it installed for over a year now (4.1) have never had any problems with...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.