Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

mysql_fetch_array() error

Contributor ,
Mar 26, 2007 Mar 26, 2007
Hey guys, i get this error :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/therainb/public_html/myphptests/view_files.php on line 17
I tried lots of diff things to fix it, one one them was adding the '@' just before the mysql_fecth...
while ($row = @mysql_fetch_array ($result, MYSQL_ASSOC)) {

which did get rid of the error but, it says : There are currently no files to be viewed.

Does someone know how to fix this , please ?

Here is my code:

<?php # Script 12.9 - view_files.php
// This page displays the files uploaded to the server.

// Set the page title and include the HTML header.
$page_title = 'View Files';
include ('./includes/header.html');

require_once ('mysql_connect.php'); // Connect to the database.

$first = TRUE; // Initialize the variable.

// Query the database.
$query = "SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description, DATE_FORMAT (date_entered, '%M %e, %Y') AS d FROM uploads ORDER BY date_entered DESC";
$result = mysql_query ($query);

// Display all the URLs.
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

// If this is the first record, create the table header.
if ($first) {
echo '<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="20%"><font size="+1">File Name</font></td>
<td align="left" width="40%"><font size="+1">Description</font></td>
<td align="center" width="20%"><font size="+1">File Size</font></td>
<td align="left" width="20%"><font size="+1">Upload Date</font></td>
</tr>';

$first = FALSE; // One record has been returned.

} // End of $first IF.

// Display each record.
echo "<tr>
<td align=\"left\"><a href=\"download_file.php?uid={$row['upload_id']}\">{$row['file_name']}</a></td>
<td align=\"left\">" . stripslashes($row['description']) . "</td>
<td align\"center\">{$row['fs']}kb</td>
<td align=\"left\">{$row['d']}</td>
</tr>\n";

} // End of while loop.

// If no records were displayed...
if ($first) {
echo '<div align="center">There are currently no files to be viewed.</div>';
} else {
echo '</table>'; // Close the table.
}

mysql_close(); // Close the database connection.
include ('./includes/footer.html');
?>


THANK YOU SO MUCH
TOPICS
Server side applications
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 27, 2007 Mar 27, 2007
LuisDesigns wrote:
> Hey guys, i get this error :
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
> resource in /home/therainb/public_html/myphptests/view_files.php on line 17

> I try lots of diff things to fix it, one one them was adding the '@' just
> before the mysql_fecth...
> while ($row = @mysql_fetch_array ($result, MYSQL_ASSOC)) {
>
> which did get rid of the error but, it says : There are currently no files
> to be viewed.


No, it didn't get rid of the error. It got rid of the error message. @
is the error control operator, and PHP beginners should be banned from
using it until they learn what error messages mean. Sorry to sound
harsh, but error messages are there to help you. The error control
operator should be added only after you have verified that the script is
working correctly. Its purpose is to hide error messages that might be
of assistance to malicious attackers.

Read the error message again. It says that the argument you supplied to
mysql_fetch_array() isn't a valid MySQL result resource. In other words,
there's something wrong with your SQL query. To find out what it is, you
need to display the error message returned by MySQL

Change this:

> $result = mysql_query ($query);

To this:

$result = mysql_query($query) or die(mysql_error());

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 27, 2007 Mar 27, 2007
ok, i fix it, not sure which of these problems were , a lil confused here.

i went to by add_file.php and removed the '@' from here:
if ( @move_uploaded_file($_FILES[$filename]['tmp_name'], "uploads/$upload_id")) {

and in the view_files.php 'where the problem actualy was' i changed this:
$query = "SELECT upload_id, file_name, ROUND(file_size/1024) AS fs, description, DATE_FORMAT i have a space here(date_entered, '%M %e, %Y')

Question, why do people recommend to add the @ sign if it not good idea to use it ???

just wondered.
Thanks again
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 27, 2007 Mar 27, 2007
hey David, the mysql_fetch_array() error has been solved but when i open my view.files.php it doesn't show the FILE NAMES.
look here:
http://therainbowpride.com/myphptests/view_files.php

it was suppose to show the files name. I looked back on the code but can seem the problem
txs
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 28, 2007 Mar 28, 2007
LuisDesigns wrote:
> hey David, the mysql_fetch_array() error has been solved but when i open my
> view.files.php it doesn't show the FILE NAMES.
> look here:
> http://therainbowpride.com/myphptests/view_files.php

You have obviously solved the problem, because the file names are there now.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 27, 2007 Mar 27, 2007
Thank you so much for that David. I have change the code as u recommended me and now i get this error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '(date_entered, '%M %e, %Y') AS d FROM uploads ORDER BY date_ent

btw - i have purchased the 2 books recommended to me. Both by you.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 27, 2007 Mar 27, 2007
LuisDesigns wrote:
> Thank you so much for that David. I have change the code as u recommended me
> and now i get this error:
> You have an error in your SQL syntax. Check the manual that corresponds to
> your MySQL server version for the right syntax to use near '(date_entered, '%M
> %e, %Y') AS d FROM uploads ORDER BY date_ent


MySQL error messages always use the expression "near" followed by part
of your SQL query. It means the error is immediately before the section
quoted. Seeing that error message made it easy to spot the problem. It's
here:

DATE_FORMAT (date_entered, '%M %e, %Y')

There must be no space between a MySQL function and the opening
parenthesis. It should be this:

DATE_FORMAT(date_entered, '%M %e, %Y')

> btw - i have purchased the 2 books recommended to me. Both by you.

Thanks, I hope you find them useful.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 27, 2007 Mar 27, 2007
Thanks you everyone for the support.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 27, 2007 Mar 27, 2007
i hear ya, will keep my eyes more opened , lol.

Thanks again
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Mar 28, 2007 Mar 28, 2007
Yes we have, thank you so much.
Hey , i had the books delivered to my house today, and i noticed that the PhP for Dreamweaver 8 shows how to create a photo gallery page. Do you think that it will be easy for me to have a page for my visitors to create their own gallery also in there?
I am really excited about reading your books. Thanks Again David.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 29, 2007 Mar 29, 2007
LATEST
LuisDesigns wrote:
> Yes we have, thank you so much.
> Hey , i had the books delivered to my house today, and i noticed that the PhP
> for Dreamweaver 8 shows how to create a photo gallery page. Do you think that
> it will be easy for me to have a page for my visitors to create their own
> gallery also in there?

Doable? Yes. Easy? No. It would involve a lot of setting up.

> I am really excited about reading your books. Thanks Again David.

I hope you find them useful.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines