Jump to content

Recommended Posts

<?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

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>";
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.