Page 1 of 1

Why isn't the code displaying database content???

Posted: Sun Jul 23, 2006 9:01 pm
by cturner
My code is displaying the date_entered and not the article. Can someone please tell me why? Thanks in advance. :?
Here is the code for the displaying the content:

Code: Select all

require "config2.php";

$article_id = $_GET['article_id'];
$article = mysql_real_escape_string($_POST['article']);

$query = "SELECT * FROM articles";

if ($r = mysql_query ($query)) {

 $str = "";
      while ($row = mysql_fetch_array ($r)) { 
				$str .= '<p>'. $row['date_entered'] . '<br />' . $row['article'] . '<br />
                <a href="modify_article.php?id="'. $_GET['article_id'] .'">Modify</a>
                <a href="delete_article.php?id="'. $_GET['article_id'] .'">Delete</a>
                </p>';
        }
       if($str==="")
       {
          echo 'No entries to be displayed. <a href="diary.php">Click here</a> to return to the main page.';
       } else {
          echo $str;
       }
}
} else {
	print "You are not logged in. Please <a href=login.php>click here</a> to login.";
}
mysql_close();
And here is the code for adding the content to the database:

Code: Select all

require "config2.php";
$article_id = $_GET['article_id'];
$article = mysql_real_escape_string($_POST['article']);
$date_entered = date("j F, Y");
$insert = "INSERT INTO articles (`id`, `article_id`, `article`, `date_entered`) VALUES
(0, '$article_id', '$article', '$date_entered')" or die ('<p>Could not insert data into the table.</p>');

	if (mysql_query ($insert)) {
		print '<p>The diary entry has been added. <a href="view_articles.php">Click here</a> to continue.</p>';
	} else {
		print "<p>Could not add the entry because: <b>" . mysql_error() .
		"</b>. The query was $query.</p>";
	}

mysql_close();

Posted: Sun Jul 23, 2006 9:35 pm
by Christopher
The code looks like it should work. Have you look at the database directly to see if there is actually data in the article field?