0

Hi.

First off, I'm new to PHP. So you will have to be real specific with your answers.

I'm trying to create a comments section under my news articles and I'm having a real hard time with it. At first I was wanting to make it so that a new comments table is created for every news post, but I was told to just make it one table.

I really don't know what I'm doing wrong here. I get an error message saying "Query was empty".

News Article (Works):

mysql_select_db($database_mgslog, $mgslog);
$query_news = sprintf("SELECT * FROM newsarticle WHERE id = %s", GetSQLValueString($colname_news, "int"));
$news = mysql_query($query_news, $mgslog) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);

Comment Section (Doesn't Work):

mysql_select_db($database_mgslog, $mgslog);
$query_news = ("SELECT * FROM newscomments WHERE nid = id");
$news = mysql_query($query_newscomments, $mgslog) or die(mysql_error());
$row_news = mysql_fetch_assoc($news);
$totalRows_news = mysql_num_rows($news);

Form Field (For the comment section that doesn't work):

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" />
 
<p>Name : <input type="text" name="name" length="25" maxlength="50" value="<?php if(isset($_POST['name'])) echo $_POST['name'];?>" /></p>
 
<p>Comment : <textarea columns="6" rows="6" name="comment"><?php if(isset($_POST['comment'])) echo $_POST['comment'];?></textarea></p>
 
<p><input type="submit" name="submit" value="Submit Comment" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>

News Table
[img]http://img827.imageshack.us/img827/3512/newsx.gif[/img]

Comments Table
[img]http://img59.imageshack.us/img59/8632/commentsv.gif[/img]

Edited by louie540: n/a

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by broj1
0

I thing the cause of trouble could be in your query in a comment section (line 2):

$query_news = ("SELECT * FROM newscomments WHERE nid = id");

id should probably be a PHP variable, maybe $id? Just a guess.

$query_news = ("SELECT * FROM newscomments WHERE nid = $id");
0

You will probably have to do some basic debugging like put echo or die statement to examine your query. I would put a line after line 2 (comment section):

echo($query_news);

and then copy the displayed query from the browser to phpmyadmin (or any other gui to mysql server or even through shell) and run it there. Then you can see exactly what query gets passed to the server and whether there are any records that should be returned.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.