Jump to content

problem with comments section on blog...


Noskiw

Recommended Posts

<?php

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("blog", $connect) or die(mysql_error());

if(!$_POST['submit']){
echo "

<form action='index.php?p=blog&p=comment' method='POST'>

<table width='100%'>

<tr>

<td width='9%' valign='top'>
Your Name:
</td>

<td valign='top'>
<input type='text' name='name' maxlength='32' />
</td>

</tr>

<tr>

<td valign='top'>
Your Email:
</td>

<td>
<input type='text' name='email' maxlength='35' />
</td>

</tr>

<tr>

<td valign='top'>
Your Post:
</td>

<td>
<textarea cols='50' rows='5' name='comment' maxlength='250'></textarea>
<p><input type='submit' name='submit' value='Post' />
</td>

</tr>

<br />

<table width='100%'>
<tr><td>Available BBCode: [b], [/b], [u], [/u], [i], [/i], , </td></tr>
</table>

</table>

</form>";
}else{
$pid = $_GET['pid'];
$pid = $_POST['pid'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$date = date("Y-m-d");
    $time = date("H:i:s");
    
    if($name && $email && $comment){
    	$query = mysql_query("INSERT INTO comments VALUES('','" . $pid . "','" . $name . "','" . $email . "','" . $comment . "','" . $date . "','" . $time . "')");
    	echo "<hr />Please wait... <meta http-equiv='refresh' content='2'>\n";
    }
}

?>

 

my problem with this code, is that when i enter the post into the table, The comment column shows up as a "0" and so does the "pid" column

 

<?php

$title = "Blog";

$connect = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("blog", $connect) or die(mysql_error());

function bbcode($string)
{


    if ($string) {


        $bbcode_array = array('[b]', '[/b]', '[u]', '[/u]', '[i]', '[/i]', '[code]',
            '

', '', '', ':P');

 

 

        $bbcode_array_2 = array('<b>', '</b>', '<u>', '</u>', '<i>', '</i>',

            '<center><div style="width:90%;padding:3px;background-color:#000099;color:#FFFFFF;border:2px solid;">',

            '</div></center>', '<img src="', '">',

            '<img src="http://localhost/images/P.gif" />');

 

 

        $new_string_2 = str_ireplace($bbcode_array, $bbcode_array_2, $string);

 

 

        return $new_string_2;

 

 

    }

}

 

//start pagination

$query = "SELECT * FROM blog ORDER BY id DESC";

include ('pagination2.php');

$paginator = new pagination($_GET['page'], $query);

$paginator->results_per_page = 2;

$paginator->padding(2);

$paginator->link_prefix =

    'http://localhost/dynamic web page/index.php?p=blog&page=';

$paginator->link_suffix = '';

$paginator->page_nums_separator = ' | ';

$paginator->paginate();

 

echo "<h1>Blog</h1>\n";

 

$query = mysql_query("SELECT * FROM blog ORDER BY id DESC");

 

if (mysql_num_rows($query) == 0) {

    echo "<hr />There are no posts yet, make the first in the admin section!\n";

}

 

echo "<h2>Newest Post!</h2>";

 

while ($row = mysql_fetch_assoc($paginator->resource())) {

    echo "<hr />";

    $id2 = $row['id'];

    $title2 = $row['title'];

    $name = $row['name'];

    $email = $row['email'];

    $post = $row['post'];

    $date = $row['date'];

    $time = $row['time'];

 

    echo "<h3>Title: " . $title2 . "</h3><table width='100%'><tr><td><b>Posted by: " .

        $name . "(" . $email . ") at " . $time . " on " . $date .

        "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags(substr($post, 0, 201),

        wordwrap($post, 118, "<br />", true))));

    if (strlen($post) > 201) {

        echo "...<a href='./index.php?p=blog&p=post&id=" . $id2 .

            "'>Read More</a><hr /><h3>Comments</h3>\n";

    } else {

        echo "<hr /><h3>Comments</h3>\n";

    }

    $query2 = mysql_query("SELECT * FROM comments WHERE pid='" . $id2 . "'ORDER BY id DESC");

 

    if (mysql_num_rows($query2) == 0) {

        echo "No comments on this topic... yet. Please feel free to leave one <a href='index.php?p=blog&p=comment&pid=" . $id2 . "'>Here</a>!";

        echo "</td></tr></table>\n";

    } else {

    while ($row2 = mysql_fetch_assoc($query2)) {

        $id3 = $row2['id'];

        $pid = $row2['pid'];

        $pid .= $row['id'];

        $name2 = $row2['name'];

        $email2 = $row2['email'];

        $comm = $row2['comment'];

        $date2 = $row2['date'];

        $time2 = $row2['time'];

 

        echo "<table width='60%'><tr><td><b>Posted by: " . $name2 . "(" . $email2 .

            ") at " . $time2 . " on " . $date2 . "</b></td></tr><tr><td>" . nl2br(bbcode(strip_tags

            (wordwrap($comm, 118, "<br />", true))));

    }

        echo "Place a post <a href='index.php?p=blog&p=comment&pid=" . $id2 .  "'>Here</a>!";

    }

}

 

echo $paginator;

 

echo "<hr />\n";

 

echo "Are you an admin? <a href='index.php?p=blog&p=credentials'>Place a post</a>\n";

 

?>[/code]

 

my problem with this code is that it wont display the comment... Please can someone help me?

Link to comment
https://forums.phpfreaks.com/topic/180697-problem-with-comments-section-on-blog/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.