JayJabber Posted June 9, 2011 Share Posted June 9, 2011 <?php include 'config.php'; $news = mysql_query("SELECT * FROM ". $_GET['sitename'] ."news ORDER BY id DESC"); if(mysql_num_rows($news) > 0) { while($n = mysql_fetch_array($news)) { print "<h1>" . stripslashes($n['title']) . "</i></h1>"; print "<i><b>" . $n['date'] . "</b></i><br>"; print nl2br(stripslashes($n['news'])) ."<br><br>"; if(isset($_SESSION['username'])) { echo "<p><a href='editnews.php?id=$n[id]'>Edit</a> || <a href='dnews.php?id=$n[id]'>Delete</a></p>"; } } } else { echo "<p>There is no news.</p>"; } if(!isset($_SESSION['username'])) { echo "<a href='login.php'>Login</a>"; } else { echo "<a href='logout.php'>Logout</a>"; } ?> I've coded this up and i don't see why it does not connect the database by that i mean connect to that database. The $_GET function is just to get the site name . please help Link to comment https://forums.phpfreaks.com/topic/238921-news-function-wont-work/ Share on other sites More sharing options...
Pikachu2000 Posted June 9, 2011 Share Posted June 9, 2011 What error(s) is it returning? Link to comment https://forums.phpfreaks.com/topic/238921-news-function-wont-work/#findComment-1227704 Share on other sites More sharing options...
JayJabber Posted June 9, 2011 Author Share Posted June 9, 2011 No errors are shown but the message There is no news shows Link to comment https://forums.phpfreaks.com/topic/238921-news-function-wont-work/#findComment-1227710 Share on other sites More sharing options...
Pikachu2000 Posted June 9, 2011 Share Posted June 9, 2011 See if this shows any errors. I added some basic error reporting to the query execution. include 'config.php'; $query = "SELECT * FROM ". mysql_real_escape_string($_GET['sitename']) ."news ORDER BY id DESC"; if( !$news = mysql_query($query) ) { die("<br>Query $query<br>Failed with error: " . mysql_error()); } if(mysql_num_rows($news) > 0) { while($n = mysql_fetch_array($news)) { print "<h1>" . stripslashes($n['title']) . "</i></h1>"; print "<i><b>" . $n['date'] . "</b></i><br>"; print nl2br(stripslashes($n['news'])) ."<br><br>"; if(isset($_SESSION['username'])) { echo "<p><a href='editnews.php?id=$n[id]'>Edit</a> || <a href='dnews.php?id=$n[id]'>Delete</a></p>"; } } } else { echo "<p>There is no news.</p>"; } if(!isset($_SESSION['username'])) { echo "<a href='login.php'>Login</a>"; } else { echo "<a href='logout.php'>Logout</a>"; } Link to comment https://forums.phpfreaks.com/topic/238921-news-function-wont-work/#findComment-1227711 Share on other sites More sharing options...
JayJabber Posted June 11, 2011 Author Share Posted June 11, 2011 Query SELECT * FROM news ORDER BY id DESC Failed with error: Table 'site.news' doesn't exist :-\ Link to comment https://forums.phpfreaks.com/topic/238921-news-function-wont-work/#findComment-1228290 Share on other sites More sharing options...
JayJabber Posted June 11, 2011 Author Share Posted June 11, 2011 Solved, simply changed t: ". mysql_real_escape_string($info['sitename']) ."news Thanks for help! Link to comment https://forums.phpfreaks.com/topic/238921-news-function-wont-work/#findComment-1228292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.