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>'; } Quote Link to comment 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? Quote Link to comment 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: Quote Link to comment 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>'; } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.