Jump to content

Blog comment system not working


joshgarrod

Recommended Posts

Hi all, I am up against my biggest challenge yet! I have been asked to code a blog and the only thing that i can't get working poperly is the comment system. The following code is an include on the article page:

 

<?php
	error_reporting(E_ALL);
		$con = mysql_connect("host","user","pass");
		if (!$con)
			{
			  die('Could not connect: ' . mysql_error());
			 }
			mysql_select_db("quest", $con);
			$db = mysql_select_db("quest", $con);

			if ($_POST['submit']) {

	$comment = mysql_real_escape_string($_POST['comment']);
	$name = mysql_real_escape_string($_POST['name']);
	$submitted = mysql_real_escape_string($_POST['timedate']);
	$live = "No";
	$articleref = mysql_real_escape_string($_POST['articleref']);
	$page = mysql_real_escape_string($_POST['page']);


        $SQL = " INSERT INTO comments ";
        $SQL .= " (comment, name, submitted, live, articleref) VALUES ";
        $SQL .= " ('$comment', '$name', '$submitted', '$live', '$articleref') ";

        
        $result = mysql_db_query($db,$SQL,$cid);

        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

			//show comments (if any) code
			$query = mysql_query("SELECT * FROM comments WHERE `articleref` = '$page'");	

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

				echo "<p>There are currently no comments for this article - please use the form below if you wish to make a comment</p>";

				  }else{

					while($info = mysql_fetch_array($query)){

					$comment = $info ['comment'];
					$name = $info ['name'];
					$submitted = $info ['submitted'];
					$live = $info ['live'];

					if ($live == "Yes") {

					echo "<p>Comment by - $name on $submitted</p>
					<p>$comment</p><hr class=\"hr\" width=90%>";

					}
					else {

					}

					}
					}

        //header("location:thanks_comment.php");
	//exit();

    }

			?>

 

From this I am getting the following errors:

 

Notice: Undefined variable: cid in C:\Users\website\comments.php on line 26

 

Warning: mysql_db_query(): supplied argument is not a valid MySQL-Link resource in C:\Users\website\comments.php on line 26

ERROR: INSERT INTO comments (comment, name, submitted, live, articleref) VALUES ('comment text, User Name', 'Tuesday 12th June 2009', 'No', '1')

Link to comment
https://forums.phpfreaks.com/topic/162035-blog-comment-system-not-working/
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.