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

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
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
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.