Jump to content

[SOLVED] why am i getting this error?


Renlok

Recommended Posts

ive know idea why im getting this error when i load the page i get the error
[quote]
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/renlok/public_html/roe/news.php on line 13
[/quote]
it also then loads up the first entery in the database.

the code for the page is
[code]
<?php
include("includes/header.php");

echo "<center>";
$newsquery = "SELECT * FROM news WHERE type='1'";
$news = mysql_query($newsquery);
$newsheader =<<<EOD
<table width="75%" border="1" style="border-collapse: collapse">
  <tr>
    <td>News</td>
  </tr>
EOD;
while($newinfo = mysql_fetch_array($news))
{
$news = $newinfo['news'];
$name = $newinfo['name'];
$posted = $newinfo['posted'];
$newsmain .=<<<EOD
<tr>
    <td><u>$name</u><br>$news<p>Posted at: $posted</td>
</tr>
EOD;
}
$newsfooter = "</table>";
$news =<<<NEWS
$newsheader
$newsmain
$newsfooter
NEWS;

echo $news;
echo "</center>";

include("includes/footer.php");
?>
[/code]

as someone asked before, all the db connection info is in 'includes/header.php'
Link to comment
https://forums.phpfreaks.com/topic/32563-solved-why-am-i-getting-this-error/
Share on other sites

You're getting that error because you have some sort of error in your query. Change these lines
[code]<?php
$newsquery = "SELECT * FROM news WHERE type='1'";
$news = mysql_query($newsquery);
?>[/code]

to
[code]<?php
$newsquery = "SELECT * FROM news WHERE type='1'";
$news = mysql_query($newsquery) or die("Problem with the query: $newsquery<br>".mysql_error());
?>[/code]

This should output the error.

Ken
try this

[code]<?php
include("includes/header.php");

echo "<center>";
$newsquery = "SELECT * FROM news WHERE type='1'";
$news = mysql_query($newsquery);
if($news){
$newsheader =<<<EOD
<table width="75%" border="1" style="border-collapse: collapse">
  <tr>
    <td>News</td>
  </tr>
EOD;
while($newinfo = mysql_fetch_array($news))
{
$news = $newinfo['news'];
$name = $newinfo['name'];
$posted = $newinfo['posted'];
$newsmain .=<<<EOD
<tr>
    <td><u>$name</u><br>$news<p>Posted at: $posted</td>
</tr>
EOD;
}
$newsfooter = "</table>";
$news =<<<NEWS
$newsheader
$newsmain
$newsfooter
NEWS;

echo $news;
echo "</center>";
}else{
echo "There was an error.<br />\n"
.mysql_error();
}
include("includes/footer.php");
?>
[/code]
IF the query failed, the error should show and say why
There is a problem with your query. To find out what is wrong change this:
[code]$news = mysql_query($newsquery);[/code]
to this:
[code]$news = mysql_query($newsquery) or die("Error with query <pre>{$newsquery}</pre>:<br />" . mysql_error());[/code]
ive tryed all of your ideas but it always come back with the same thing thats no change but i did notice if i removed
[code]while($newinfo = mysql_fetch_array($news))[/code]
and jey left
[code]$newinfo = mysql_fetch_array($news);[/code]
in its place i dont get an error message but again only one result is returned.
Know thy code (or at least proof read it)  ::)

The code in the while loop overwrites the [b]$news[/b] variable -
[code]$news = $newinfo['news'];[/code]However, this [b]was[/b] the result resource from the query -
[code]$news = mysql_query($newsquery);[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.