- 1

please you guys should help me debug this code

index.php <title> </title> </head> <body> <?php $db=mysql_connect ("localhost", "root", ""); mysql_select_db("practice"); $sql="SELECT * FROM info_news ORDER by news_id DESC"; $result=mysql_query($sql, $db); $newsid='news_id'; echo "<h1>Latest News: </h1><br>"; $i=1; while($myrow=mysql_fetch_array($result)) { echo $myrow['news_title']; echo "<br>"; echo "<a href=read_more.php?newsid=$myrow[news_id]>Read More...</a><br>"; echo "<hr>"; $i=$i+1; if($i>5) break; } ?> </body> </html> read_more.php <?php $db=mysql_connect("localhost", "root", ""); mysql_select_db("practice", $db); $newsid=$_REQUEST['newsid']; $query = "SELECT news_title,news_full_content FROM info_news WHERE news_id='$newsid'"; $result=mysql_query($query, $db) or die (mysql_error()); $row= mysql_fetch_array($query); if($newsid=='news_id'){ echo $row['news_title']; echo "<br>"; echo $row['news_full_content']; } echo "<br><br><a href=\"javascript:self.history.back();\"><-- Go Back</a>"; ?>

15th Jun 2017, 12:06 AM
AUDU OCHOYODA BRIGHT
AUDU OCHOYODA BRIGHT - avatar
1 Resposta
+ 4
I cannot run your code, as it require connexion to your local database, but anyway, you have at least a problem with the line: echo "<a href=read_more.php?newsid=$myrow[news_id]>Read More...</a><br>"; ... wich can be right write (not the only way): echo "<a href=read_more.php?newsid=".$myrow['news_id'].">Read More...</a><br>"; Hope this is enough for fixing your code ;)
15th Jun 2017, 12:30 AM
visph
visph - avatar