MishieMoo Posted January 3, 2008 Share Posted January 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/ Share on other sites More sharing options...
gurhy Posted January 3, 2008 Share Posted January 3, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/#findComment-428957 Share on other sites More sharing options...
MishieMoo Posted January 3, 2008 Author Share Posted January 3, 2008 That's not the problem. I added the extra `s because those seem to make the querys work more times than not, but as of right now that line isn't even getting executed xD The second one stops at the insert right now. Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/#findComment-428960 Share on other sites More sharing options...
teng84 Posted January 3, 2008 Share Posted January 3, 2008 out a die in all you query to see the error message... the error have means that your query failed or you pass a data that is not resource Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/#findComment-428964 Share on other sites More sharing options...
MishieMoo Posted January 3, 2008 Author Share Posted January 3, 2008 Hahaha...I'm such an idiot o.O The first problem's solved. I had the wrong table name xD I need to start writing these down. Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/#findComment-428967 Share on other sites More sharing options...
teng84 Posted January 3, 2008 Share Posted January 3, 2008 if you put a die (mysql_error()) you will notice that ,,, earlier Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/#findComment-428969 Share on other sites More sharing options...
MishieMoo Posted January 3, 2008 Author Share Posted January 3, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/#findComment-428972 Share on other sites More sharing options...
MishieMoo Posted January 3, 2008 Author Share Posted January 3, 2008 Nevermind. I got it. Solved. Quote Link to comment https://forums.phpfreaks.com/topic/84232-solved-one-query-problem-left/#findComment-428995 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.