S A N T A Posted April 26, 2008 Share Posted April 26, 2008 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 More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 you have to execute the sql before fetching anything $sql = "SELECT * FROM categories"; $result = mysql_query($sql) or die(mysql_error()); $a_row = mysql_fetch_assoc($result); Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-527872 Share on other sites More sharing options...
S A N T A Posted April 26, 2008 Author Share Posted April 26, 2008 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) Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-527875 Share on other sites More sharing options...
S A N T A Posted April 26, 2008 Author Share Posted April 26, 2008 please help i dont know why it wont work Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-527912 Share on other sites More sharing options...
BlueSkyIS Posted April 26, 2008 Share Posted April 26, 2008 i don't see where you connect to the database server and select a database. is it in config.php or missing? Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-527913 Share on other sites More sharing options...
darkfreaks Posted April 26, 2008 Share Posted April 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-527925 Share on other sites More sharing options...
S A N T A Posted April 27, 2008 Author Share Posted April 27, 2008 <?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 Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-528051 Share on other sites More sharing options...
darkfreaks Posted April 27, 2008 Share Posted April 27, 2008 where is the connection line i am not seeing it ??? Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-528075 Share on other sites More sharing options...
Fadion Posted April 27, 2008 Share Posted April 27, 2008 This thread is hilarious. SANTA, read the basics first. Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-528080 Share on other sites More sharing options...
S A N T A Posted April 27, 2008 Author Share Posted April 27, 2008 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"); ?> Link to comment https://forums.phpfreaks.com/topic/103059-solved-mysql_fetch_assoc-error/#findComment-528510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.