Jump to content

[SOLVED] mysql_fetch_assoc error


S A N T A

Recommended Posts

well i get an error from this code (This code is suppost to display data from a database)

 

<?php
require("config.php");

if(isset($_GET['id']) == TRUE) {
if(is_numeric($id) == FALSE) {
	$error = 1;
}
if($error == 1) {
header("Location: " . $config_basedir . "/viewcat.php");
}
else {
	$validcat = $_GET['id'];
}
}
else {
$validcat = 0;
}

$sql = "SELECT * FROM categories";
$result = mysql_fetch_assoc($sql);

while($row = mysql_fetch_assoc($result)) {
if($validcat == $row['id']) {
	echo "<strong>" . $row['cat'] . "</strong><br />";

	$entriessql = "SELECT * FROM entries WHERE cat_id = " . $validcat . " ORDER BY dateposted DESC;";

	$entriesres = mysql_query($entriessql) or die(mysql_error(). "   in $sql");
	$numrows_entries = mysql_num_rows($entriesres);

	echo "<ul>";
	if($numrows_entries == 0) {
		echo "<li>No entries!</li>";
	}
	else {
		while($entriesrow = mysql_fetch_assoc($entriesres)) {
			echo "<li>" . date("D jS F Y g.iA", strtotime($entriesrow['dateposted'])) . " - <a href='viewentry.php?id=" . $entriesrow['id'] . "'>" . $entriesrow['subject'] . "</a></li>";
		}
	}
	echo "</ul>";
}
else {
	echo "<a href='viewcat.php?id=" . $row['id'] . "'>" . $row['cat'] . "</a><br />";
	}
}

require("footer.php");
?>

and these are the errors

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\viewcat.php on line 20

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\viewcat.php on line 22

HELP ME

 

ps: im a noob :)

Link to comment
https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/
Share on other sites

gave me these errors:

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\viewcat.php on line 20

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\viewcat.php on line 20
Access denied for user 'ODBC'@'localhost' (using password: NO)

Please paste the code for connect.php

 

 

mabe an issue with how ou are calling it.

 

 

first make sure you have defined a user for your database table and give it unlimited permissions for the database. otherwise you will have trouble connecting i have seen this issue before. ;D

<?php

$dbhost = "Localhost";
$dbuser = "root";
$dbpassword = "";
$dbdatabase = "blogtastic";

$config_blogname = "MY BLOG";
$config_author = "A NAME";
$config_basedir = "http://localhost";

?>

 

is for the config.php

 

and i havn't had problems connecting so far but its just this that i have had problems with

ok so i tried to add a some connect thing but i get 1 more error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\viewcat.php on line 24

 

heres the code

 

<?php

require("config.php");

if(isset($_GET['id']) == TRUE) {
if(is_numeric($id) == FALSE) {
	$error = 1;
}
if($error == 1) {
header("Location: " . $config_basedir . "/viewcat.php");
}
else {
	$validcat = $_GET['id'];
}
}
else {
$validcat = 0;
}
$db = mysql_connect($dbhost, $dbuser);
$sql = "SELECT * FROM categories";
$result = mysql_query($sql);
mysql_select_db($dbdatabase, $db);

while($row = mysql_fetch_assoc($result)) {
if($validcat == $row['id']) {
	echo "<strong>" . $row['cat'] . "</strong><br />";

	$entriessql = "SELECT * FROM entries WHERE cat_id = " . $validcat . " ORDER BY dateposted DESC;";

	$entriesres = mysql_query($entriessql)or die(mysql_error(). "   in $sql");
	$numrows_entries = mysql_num_rows($entriesres);

	echo "<ul>";
	if($numrows_entries == 0) {
		echo "<li>No entries!</li>";
	}
	else {
		while($entriesrow = mysql_fetch_assoc($entriesres)) {
			echo "<li>" . date("D jS F Y g.iA", strtotime($entriesrow['dateposted'])) . " - <a href='viewentry.php?id=" . $entriesrow['id'] . "'>" . $entriesrow['subject'] . "</a></li>";
		}
	}
	echo "</ul>";
}
else {
	echo "<a href='viewcat.php?id=" . $row['id'] . "'>" . $row['cat'] . "</a><br />";
	}
}

require("footer.php");
?>

 

 

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.