joshgarrod Posted June 13, 2009 Share Posted June 13, 2009 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') Quote Link to comment Share on other sites More sharing options...
keeps21 Posted June 13, 2009 Share Posted June 13, 2009 You're using $cid in your query on line 26 but $cid hasn't been definied anywhere, in other words $cid doesn't exist. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.