473,503 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MySql_fetch_array() error in PHP

1 New Member
I got the following message when trying to do a mysql php query:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apa....

Can anyone help offer suggestions?

Here is the code:
$query = "SELECT title, role_name, CONCAT(first_name, ' ', last_name) AS name FROM actors, roles, movies WHERE actors.act_id = roles.act_id AND roles.movie_id = movies.movie_id AND year > 1999 ORDER BY year;";

$result = @mysql_query ($query);
// Print the results
echo '<table><tr><td align="left"><b>Movie Title </b></td><td align="left"><b>Role Name </b></td><td align="left"><b>Actor</b></td></tr>';
while ($row = mysql_fetch_array
($result, MYSQL_ASSOC))
Mar 22 '07 #1
3 2321
ak1dnar
1,584 Recognized Expert Top Contributor
Next time please enclose your php lines with PHP tags :)

Since i don't have your Table structure i didn't check the SQL Query.
If this is not working post the SQL script with some sample values.
then i can check it in my end.

[PHP]<?php
$query = "SELECT title, role_name, CONCAT(first_name, ' ', last_name) AS name FROM actors, roles, movies WHERE actors.act_id = roles.act_id AND roles.movie_id = movies.movie_id AND year > 1999 ORDER BY year;";

$result = mysql_query($query);
// Print the results
echo '<table><tr><td align="left"><b>Movie Title </b></td><td align="left"><b>Role Name </b></td><td align="left"><b>Actor</b></td></tr>';
while ($row = mysql_fetch_array($result))
{
echo '<tr>
<td align="left">'.$row['title'].'</td><td align="left">'.$row['role_name'].'</td><td align="left">'.$row['name'].'</td>
</tr>';
}
echo '<table>';
?>[/PHP]
Mar 22 '07 #2
code green
1,726 Recognized Expert Top Contributor
Get rid of the idiotic '@' symbol then you might see why it is failing. As the error occurs here
Expand|Select|Wrap|Line Numbers
  1. $result = @mysql_query ($query);
. Your query is wrong. We don't know why without your table
Mar 22 '07 #3
ronverdonk
4,258 Recognized Expert Specialist
You suffer from the same shortcoming many developers have: you must always check the results of any database or file related command!

In this case the problem is that your query returns an error, so you must capture that error before you continue. Like this:
Expand|Select|Wrap|Line Numbers
  1. $result = mysql_query ($query) 
  2.     or die("Query error: " . mysql_error());
Ronald :cool:
Mar 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7956
by: Noel Wood | last post by:
Hello I keep getting a warning ... Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in "name of my php file" when I run this query.... SELECT Menu_Item,...
4
6999
by: Theo | last post by:
hi all this is probably another simple one, but the web doesnt seem to have an answer that I can find. Veeeery simple code. each row has 10 columns. require('db.php'); $query = "SELECT *...
3
3422
by: Pratchaya | last post by:
Hi Everyone ============================================================== About PHP::: Error/Problem PHP Warning: mysql_fetch_array():...
9
7405
by: Petr Vileta | last post by:
Hi, I'm new here and excuse me if this question was be here earlier. I have a simple code <html><body> <?php <?php $link = mysql_connect("localhost", "user", "password") or die("Grr: " ....
3
9441
by: debajyoti2040 | last post by:
In config.php line 28 I have written the following lines. $query = "SELECT * FROM `users` WHERE username = '".$uname."' AND password = '".$pword."'"; # set a query $online =...
2
4623
by: Karl Groves | last post by:
I'm trying to run mysql_fetch_array with a variable in place of the optional result type constant, like so mysql_fetch_array($result, $rtype) where, obviously, $rtype is one of the three valid...
3
3076
by: Patrick | last post by:
Hi I am trying to write a simple database class to encapsulate all the database functions in one. Howerver I am having problems with while($row = mysql_fetch_array($IsResult,MYSQL_NUM)) line it...
5
6623
by: jmDesktop | last post by:
In my code I cannot figure out how to retrieve multple rows from my returned array from a class method. I have tried: <?php class myClass { private $connection; /* Class constructor */...
1
2145
by: byteit101 | last post by:
I was working with OOP, and was testing a sql result class, but it gives me the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource. I think it has...
2
3676
nomad
by: nomad | last post by:
I having troubles with this code I'm getting a error code. Please not this is not an assignment its from a book called PHP Bible. This book is loaded with errors. Warning: mysql_fetch_array()...
0
7091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7342
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7464
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4680
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
391
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.