mike12255 Posted August 19, 2009 Share Posted August 19, 2009 So i got the following query: <?php $date = date("m-d-y") . " at " . date("h:i:s"); $time = time(); $sql2 = "INSERT INTO forum_topics (`catid`,`title,`uid`,`date`,`time`,`message`) VALUES ('".$cat."','".$title."','".$_SESSION['uid']."','".$date."', '".$time."','".$msg."')"; die($sql2); $res2 = mysql_query($sql2) or die (mysql_error()); $tid = mysql_insert_id(); header("Location: index.php?act=topic&id=".$tid.""); ?> problem is my server is yelling this at me: 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 'Resource id #6' at line 1 can anyone figure out why?? appriciate the help. thanks, Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/ Share on other sites More sharing options...
abazoskib Posted August 19, 2009 Share Posted August 19, 2009 Why do you do 'die($sql2);' ? Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901569 Share on other sites More sharing options...
mike12255 Posted August 19, 2009 Author Share Posted August 19, 2009 tried to echo the query to see what it was entering it, but it didnt work, error happened before the die was inserted Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901575 Share on other sites More sharing options...
DavidAM Posted August 19, 2009 Share Posted August 19, 2009 What does this code display as the value for $sql2? I don't see anything drastically wrong with the query; assuming $cat, $title, $_SESSION['uid'] and $msg don't have anything weird in them. Are you sure this is the section causing the error? I don't see you setting values for these variables anywhere. I think the problem is earlier in the code. Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901577 Share on other sites More sharing options...
TeNDoLLA Posted August 19, 2009 Share Posted August 19, 2009 Try echoing the $sql2 variable before running the query and see if the query string looks correct. Maybe even paste it here so we can see it also. Easier to say what could be the problem. If the error happens before the whole $sql2 line, maybe it is some elsewhere in some another query? Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901579 Share on other sites More sharing options...
mike12255 Posted August 19, 2009 Author Share Posted August 19, 2009 I was wrong sorry its a diffrent query thats wrong: $cat = mss($_POST['cat']); $title = mss($_POST['title']); $msg = mss ($_POST['message']); if ($cat && $title && $msg){ $sql = "SELECT admin FROM fourm_subcats WHERE id ='".$cat."'"; i echoed that query and got this: SELECT admin FROM fourm_subcats WHERE id ='4' Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901582 Share on other sites More sharing options...
TeNDoLLA Posted August 19, 2009 Share Posted August 19, 2009 That query looks correct. Maybe use or die(mysql_error()); when running this another query and see if it gives some error? Maybe you have wrong named fields or tables in your query that doesn't exists? Like should fourm_subcats be forum_subcats instead? Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901583 Share on other sites More sharing options...
abazoskib Posted August 19, 2009 Share Posted August 19, 2009 try removing the single quotes from around the 4. Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901591 Share on other sites More sharing options...
DavidAM Posted August 19, 2009 Share Posted August 19, 2009 Take a look at the next couple of lines of code (the ones you didn't show us). Your original error message syntax to use near 'Resource id #6' at indicates some SQL statement you sent to the server has that string 'Resource id #6' somewhere in an unexpected place. It probably shouldn't be there at all. I suspect you have something like $cat = mysql_query($sql) somewhere, because 'Resource id #' is what you will see if you cast a query result to a string (using echo or building an sql string). Take a close look at all of your mysql_query() calls, paying attention to the variables you assign the result to, and what you do with that variable later. The only thing you should really do with the result is use it in a call to one of the mysql_fetch functions. Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901603 Share on other sites More sharing options...
pengu Posted August 19, 2009 Share Posted August 19, 2009 Just out of curiosity, do you have a database connection before the query? Link to comment https://forums.phpfreaks.com/topic/170943-spot-the-query-error/#findComment-901611 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.