techkid Posted September 6, 2009 Share Posted September 6, 2009 the file is blog.php what the file do is blog.php list all the content generated blog.php?act=view&id=6 <-- this one shows individual post blog.php?act=view&id=6 is not working it says Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\supp\b-class.php on line 17 here is the code for it //view the news article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM content WHERE index = '$id'"); while($row = mysql_fetch_array($sql)) { echo "<div id='post'>"; echo "<h3>" . $row['title'] . "</h3>"; echo '<a href="blog.php?act=view&id='.$row['index'].'">'.$row['title'].'</a>'; echo $row['news']; echo '<p class="postend">Posted by: '.$row['author'].' | Date:'.$row['date'].'</p></div>'; } Link to comment https://forums.phpfreaks.com/topic/173287-solved-mysql_fetch_array-problem/ Share on other sites More sharing options...
peranha Posted September 6, 2009 Share Posted September 6, 2009 Change this $sql = mysql_query("SELECT * FROM content WHERE index = '$id'"); to $sql = mysql_query("SELECT * FROM content WHERE index = '$id'") or trigger_error(mysql_error()); and see if there is an error. Are you sure that the field is index and not Index, or something like that? Link to comment https://forums.phpfreaks.com/topic/173287-solved-mysql_fetch_array-problem/#findComment-913424 Share on other sites More sharing options...
techkid Posted September 6, 2009 Author Share Posted September 6, 2009 Now I've got 2 errors Notice: 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 'index = '6'' at line 1 in C:\wamp\www\techmv.net\b-class.php on line 16 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\techmv.net\b-class.php on line 17 Here is the database scheme: Link to comment https://forums.phpfreaks.com/topic/173287-solved-mysql_fetch_array-problem/#findComment-913425 Share on other sites More sharing options...
kratsg Posted September 6, 2009 Share Posted September 6, 2009 Add die(mysql_error()) so we can see the output. (See below code for addition) //view the news article! if(isset($_GET['act']) && $_GET['act'] == "view") { $id = $_GET['id']; $sql = mysql_query("SELECT * FROM content WHERE index = '$id'"); die(mysql_error());//ADDED HERE while($row = mysql_fetch_array($sql)) { echo "<div id='post'>"; echo "<h3>" . $row['title'] . "</h3>"; echo '<a href="blog.php?act=view&id='.$row['index'].'">'.$row['title'].'</a>'; echo $row['news']; echo '<p class="postend">Posted by: '.$row['author'].' | Date:'.$row['date'].'</p></div>'; } Link to comment https://forums.phpfreaks.com/topic/173287-solved-mysql_fetch_array-problem/#findComment-913432 Share on other sites More sharing options...
peranha Posted September 6, 2009 Share Posted September 6, 2009 Can you rename the field name? index is a Mysql reserved word. if you cant you will need to change the query to $sql = mysql_query("SELECT * FROM content WHERE `index` = '$id'"); It is better to change the field name. Link to comment https://forums.phpfreaks.com/topic/173287-solved-mysql_fetch_array-problem/#findComment-913435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.