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
Share on other sites

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.