Code:
I built this myself from scratch there, its displaying comments in the database, on the right page. But when i try to add one, im getting my own error as you can see above: "error submitting comment!"
But i cant see what ive done wrong. Any ideas would be very helpful
edit: $newsid is displayed above and is set as the $_GET['id'] from fullstory.php?id=64 for example, which is working fine
Code:
<?PHP
//display comments
$query = "SELECT id, news_id, name, comment FROM news_comments WHERE news_id = $newsid order by id desc";
$result = @mysql_query($query);
if ($result){
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo 'Name: '.$row['name'].'
comment: '.$row['comment'].'
';
}
}
?>
<?PHP
//add comment
if (isset($_POST['commentsub'])){
include ('admin/connect.php');
if (empty($_POST['name'])) {
$name1 = "Guest";
} else {
$name1 = $_POST['name'];
}
if (empty($_POST['comment'])) {
$comment1 = "none";
} else {
$comment1 = $_POST['comment'];
}
if ($name1 && $comment1){
$query = "INSERT INTO news_comments (news_id, name, comment) VALUES ('$newsid', '$name1', '$comment1'";
$result = @mysql_query($query);
if ($result) {
echo '
comment was added!
';
}
else {
echo 'error submitting comment!';
}
}
}
?>
" method="post">
Name:
"/>
Comment:
<?php if(isset($_POST['comment'])) echo $_POST['comment']; ?>
But i cant see what ive done wrong. Any ideas would be very helpful
edit: $newsid is displayed above and is set as the $_GET['id'] from fullstory.php?id=64 for example, which is working fine