mysql_fetch_assoc supplied argument not valid MySQL [SOLVED]
Posted: Sun Sep 16, 2007 4:09 pm
feyd | Please use 
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I am having trouble getting this code to display correctly. I recieve this error when I try to preview the page in firefox: "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\New_Blog\viewentry.php on line 34." I have provided the code from the entire page and would appreciate it if someone could point out what I am doing wrong. Thanks.Code: Select all
<?php
require("config.php");
if(isset($_GET['id']) == TRUE) {
if(is_numeric($_GET['id']) == FALSE) {
$error = 1;
}
if($error == 1) {
header("Location: " . $config_basedir);
}
else {
$validentry = $_GET['id'];
}
}
else {
$validentry = 0;
}
require("header.php");
if($validentry == 0) {
$sql = "SELECT entries.*, categories.cat FROM entries, categories " .
"WHERE entries.cat_id = categories.id " .
"ORDER BY dateposted DESC " .
" LIMIT 1;";
}
else {
$sql = "SELECT entries.*, categories.cat FROM entries, categories " .
"WHERE entries.cat_id = categories.id
AND entries.id = " . $validentry .
"ORDER BY dateposted DESC " . "LIMIT 1;";
}
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo "<h2>" . $row['subject'] . "</h2><br />";
echo "<i>In <a href='viewcat.php?id=" . $row['cat_id'] ."'>" . $row['cat'] .
"</a> - Posted on " . date("D jS F Y g:iA",
strtotime($row['dateposted'])) .
"</i>";
echo "<p>";
echo nl2br($row['body']);
echo "</p>";
$commsql = "SELECT name FROM comments WHERE blog_id = " . $validentry .
" ORDER BY dateposted;";
$commresult = mysql_query($commsql);
$numrows_comm = mysql_num_rows($commresult);
if($numrows_comm == 0) {
echo"(<strong>" . $numrows_comm . "</strong>) comments : ";
$i = 1;
while($commrow = mysql_fetch_assoc($commresult)) {
echo "<a href='viewentry.php?id=" . $row['id'] ."#comment" . $i .
"'>" . $commrow['name'] . "</a> ";
$i++;
}
}
?>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]