Jump to content

Recommended Posts

Hi everyone,

 

I am currently making a website, with a blog. I have a database set up and all php is working fine - no errors etc... but:

 

(website link: http://creative.design-uk.biz/blog.php/)

When I display the content of each entry, the content doesn't actually show... it appears as one '<'.

And the comments - well there's no trace of them..

 

Here is the PHP code:

[pre]

//my sql connect is here

// If ID is set then -

if (isset($_GET["id"])) {

 

// Display one entry with the ID of GET, and it's comments.

 

// Function for one entry.

function constructentry($entry) {

$entry = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . stripslashes($entry["title"]) . '</a><br /><span class="date"> - ' . $entry["insert_date"] . '</span></h2>';

$entry = $entry . '<div class="spacer"></div>';

$entry = $entry . '<div class="blogentry">' . stripslashes($entry["content"]) . '</div>';

$entry = $entry . '<h3>Comments</h3>' . stripslashes(buildcomments($entry["entry_id"]));

return $entry;

}

// Function for the entry's commments.

function buildcomments($entryId) {

$commenthtml = '';

return $commenthtml;

}

 

// SQL For the entry.

$entrysql = "

select

entry_id,

title,

content,

date_format(insert_date,'%a %D %M, %y at %h o\'clock (%p)') as insert_date

from Entry

where entry_id= " . $_GET['id'] . ";";

$entries = mysql_query($entrysql)

or die("Error accessing database: " . mysql_error());

 

// SQL for comments.

$commentsql = "

select

entry_id,

comment_id,

author,

content,

date_format(insert_date, '%a %D %M, %y at %HH') as insert_date

from Comment

where approved= 1

and entry_id= " . $_GET['id'] . ";";

$comments = mysql_query($commentsql)

or die("Error accessing database: " . mysql_error());

 

$bloghtml = "";

if (mysql_num_rows($entries) > 0) {

while ($entry = mysql_fetch_assoc($entries)) {

$bloghtml = $bloghtml . constructentry($entry);

}

}

$toplinks = '';

$bottomlinks = '<p style="text-align: center;"><a href="blog.php">All Entries</a> - <a href="#wrapper">Back to top</a></p>';

} else { // If ID Isn't set then -

 

// Display all entry titles and dates.

 

// Function for all entries.

function constructentries($entry) {

$entry = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . $entry["title"] . '</a><br /><span class="date"> - ' . $entry["insert_date"] . '</span></h2>';

$entry = $entry . '<div class="spacer"></div>';

return $entry;

}

 

// Do all entries

$entrysql = "

select

entry_id,

title,

date_format(insert_date,'%a %D %M, %y at %h o\'clock (%p)') as insert_date

from Entry

order by entry_id desc;";

$entries = mysql_query($entrysql)

or die("Error accessing database: " . mysql_error());

 

$bloghtml = "";

if (mysql_num_rows($entries) > 0) {

while ($entry = mysql_fetch_assoc($entries)) {

$bloghtml = $bloghtml . constructentries($entry);

}

}

$toplinks = 'All Entries';

$bottomlinks = '<p style="text-align: center;"><a href="#wrapper">Back to top</a></p>';

}

// mysql quit is here.

[/pre]

 

Please help... I'm extremely confused! ;)

Link to comment
https://forums.phpfreaks.com/topic/50347-solved-mysql-database-php-problems/
Share on other sites

I didn't read all of you code... but:

<?php
   //code ...
      function constructentry($entry) {
         $entry = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . stripslashes($entry["title"]) . '[/url]
<span class="date"> - ' . $entry["insert_date"] . '</span></h2>';
         $entry = $entry . '<div class="spacer"></div>';
         $entry = $entry . '<div class="blogentry">' . stripslashes($entry["content"]) . '</div>';
         $entry = $entry . '<h3>Comments</h3>' . stripslashes(buildcomments($entry["entry_id"]));
         return $entry;
      }
   //code
?>

You get $entry as an Array. That's ok. Then you redefine it as a string containing '<h2>...</h2>';

So... what do you think is now in $entry? Is it an array?

but the main problem is that the PHP will not get content of entry or comments from the MySQL database.

 

No. The main problem has been described above. Fix that problem and if you still have issues, post the relevent new code.

 

And please, use the [ code ] [/ code ] (without the spaces) tags for syntax highlighting.

You can't overright your $entry variable as it holds your result. Try something like....

 

<?php
   //code ...
      function constructentry($entry) {
         $return = '<h2><a href="blog.php?id=' . $entry["entry_id"] . '">' . stripslashes($entry["title"]) . '</a>
<span class="date"> - ' . $entry["insert_date"] . '</span></h2>';
         $return .= . '<div class="spacer"></div>';
         $return .= . '<div class="blogentry">' . stripslashes($entry["content"]) . '</div>';
         $return .= . '<h3>Comments</h3>' . stripslashes(buildcomments($entry["entry_id"]));
         return $return;
      }
   //code
?>

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.