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

on bottom code

 

$find=mysql_query("SELECT MAX(comments) as maxc FROM blog WHERE `id`='$id'");

 

replace with this

 

$find=mysql_query("SELECT MAX(comments) as maxc FROM blog WHERE id='$id'");

 

 

I am looking at the rest of the code but some 1 might help better

Link to comment
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...

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.