Jump to content

[SOLVED] One query problem left!


MishieMoo

Recommended Posts

Okay, I'm getting two errors and I'd like to know why and how to fix them.  This is part of a blog comment script.

 

First: solved

...I just make silly errors xD

 

 

Next is the big problem.  Whenever I try to add a comment, I get this:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id`='10'' at line 1

 

Code for it:

<?php case "add":
            $id=$_GET['id'];
            $comment=mysql_real_escape_string(stripslashes($_POST['comment']));
            $time=date("m/d/y g:i A");
            $userid=$_SESSION['userid'];
            $user=$_SESSION['user'];
            $addcoment=mysql_query("INSERT INTO blog_comments(blog_id,entry,userid,user,date) VALUES('$id','$comment','$userid','$user','$time') WHERE `id`='$id'") or die(mysql_error());
            if($addcoment){
                $find=mysql_query("SELECT MAX(comments) as maxc FROM blog WHERE `id`='$id'");
                $current=mysql_fetch_array($find);
                $new=$current['maxc']+1;
                $update=mysql_query("UPDATE blog SET comments='$new' WHERE id='$id'");
                echo'Comment added!<meta http-equiv="refresh" content="1;url=news.php?blog=comment&id='.$id.'">';
                }
            break; ?> 

I'm not exactly sure what it means by line 1, in this case, as in my page that's the session_start(); which should have no play in this.

 

I've tried the other solutions when I've had this problem before, but none of them work.  I'd love to get this working so any help is appreciated.

 

If you need anymore information please just ask  :D

Link to comment
https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/
Share on other sites

I know.  I assumed I had the right name as I just added the table(it was blog_comments instead of blog_comment.  I've been at this computer for too long methinks).

 

Adding extra die()'s to the other code doesn't help though, as it stops executing after the first INSERT query, because of some sort of error that I don't understand...

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.