Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

You have an error in your SQL syntax... 1

Status
Not open for further replies.

rogerzebra

Technical User
May 19, 2004
216
SE
Hi again,
I get this uggly error message when I execute a search for a document in the database. Its only when the search result doesn't match any of the stored records, otherwise everything works fine.

"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 ')' at line 1"

I don't have any sql syntax at line 1?? Is there another way to debugging this thing than just using mysql_error?

Here is parts of the code
Code:
this is on line 1...<?php

$submit = $_POST["submit"];

$keywords = $_POST["keywords"];

	if(isset($submit_x) && isset($keywords))
	{
	doSearch($keywords);
	}
	else
	{
	getKeywords();
	}
	function getKeywords()
	{

?>
....css/html
...more php
...and it's not before here the sql syntax starts

$query = "SELECT articleIds FROM searchwords WHERE word in (" . implode(',', $arrWords) .") ";
	
$result=mysql_query($query) or die(mysql_error());
	if(mysql_numrows($result)>0)
	{
	while($row=mysql_fetch_array($result,MYSQL_NUM))
	{
	if(!isset($matchedarticles)) $matchedarticles .= $row[0];
	else $matchedarticles .= ",{$row[0]}";
	}

Have anyone seen this before? I can't get rid of that error message, so if anyone has a solution for this it would make my day :)
thanks /rz
 
hi sleipnir,

it's actually two queries first, the one which I already posted.
Code:
$query = "SELECT articleIds FROM searchwords WHERE word in (" . implode(',', $arrWords) .") ";

...and the second one
Code:
$aQuery = "SELECT DISTINCT articleId, title, documentLink, content AS summary FROM articles WHERE articleId IN ($matchedarticles)";
 
These:

Code:
$query = "SELECT articleIds FROM searchwords WHERE word in (" . implode(',', $arrWords) .") ";

Code:
$aQuery = "SELECT DISTINCT articleId, title, documentLink, content AS summary FROM articles WHERE articleId IN ($matchedarticles)";

are not queries. The above are PHP statements which attempt to programmatically create SQL queries and store those queries in the variables $query and $aQuery, respectively.

Do not assume that your code is functioning in such a way that it produces a well-formed query, because as the error message attests, it is not functioning in such a way.

Verify that your code has produced well-formed queries. This requires, at a minimum, that you output the queries and examine them.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
**********SOLVED*********
okey,
I find the reason myself...an easy mistake again. I was so sure it was the first query so i didn't bother to check the second. I forgot to put single quotes around the variable.

thanks anyway sleipnir :)
 
Yeah, you are right...I'm sorry I had the $query variables left. I know the difference and I usually execute my queries in phpmyadmin before i post. Unfortunately in this case i didn't test the second one. I was so sure it was something wrong with the other one.
 
brilliant
I'm glad that someone got something out of this atleast.
I have learn a lesson from this too...it seems that I have to be more careful from now on, and dare not to mess with a query ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top