Jump to content

Spot the query error!


mike12255

Recommended Posts

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

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

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

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

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

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.