Jump to content

Please help regarding syntax error


forumnz

Recommended Posts

My code is as follows and produces the error. I really don't know what to do?

 

Thanks, Sam.

 

<?php
$dest = &$_GET['dest'];
$subs = &$_GET['subs'];
$origin = &$_GET['origin'];
$keywords = &$_GET['keyword'];

if($origin != "")
{
$cat = $origin;
}

elseif($subs != "")
{
$cat = $subs;
}

elseif($dest != "")
{
$cat = $dest;
}

$trim = trim($cat);
$key = trim($keywords);

include('connectdb.php');

$sql = mysql_query("SELECT * FROM fflists WHERE aid='$trim'"); /* AND keywords LIKE '%$key%' OR business_name LIKE '%$key%'  
  ORDER BY keywords ASC"); */
  
$result = mysql_query($sql) or die(mysql_error()); 
  
while($row = mysql_fetch_array($result))
{
$name = $row['name'];
$a = $row['id'];

echo "<a href=index.php?cat=" . $a . ">" . $name . "</a><br>";
}

?>

 

Error:

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 #3' at line 1

Link to comment
Share on other sites

lets get things straight

 

1) a mysql query returns a Resource ID

2) when you attempt to use the "value" in a string of a mysql query you are goign to end up echoing out its resource id #n as it is a resource type not a string

 

the part that says

 

$sql = mysql_query("SELECT * FROM fflists WHERE aid='$trim'"); /* AND keywords LIKE '%$key%' OR business_name LIKE '%$key%' 

  ORDER BY keywords ASC"); */

 

$result = mysql_query($sql) or die(mysql_error());

 

 

is the problem

 

$result is trying to work on a resource not a text query  so either make the first $sql be equal to $result or something else simlar to remedy this

Link to comment
Share on other sites

In this segment of code

<?php
$sql = mysql_query("SELECT * FROM fflists WHERE aid='$trim'"); /* AND keywords LIKE '%$key%' OR business_name LIKE '%$key%'  
  ORDER BY keywords ASC"); */
  
$result = mysql_query($sql) or die(mysql_error()); 
?>

you are doing two mysql_query() calls, when you really should be doing only one. Change it to:

<?php
$sql = "SELECT * FROM fflists WHERE aid='$trim'"; /* AND keywords LIKE '%$key%' OR business_name LIKE '%$key%'  
  ORDER BY keywords ASC"; */
  
$result = mysql_query($sql) or die(mysql_error()); 
?>

 

Ken

Link to comment
Share on other sites

Thanks! I have got it working.

 

One more problem - i have 2 rows in my db (one with aid=138 and the other aid=139).

 

They both have keywords and names with the letter a, and when I search with keywords 'a' and aid=139, both come up, when only one should come up.

I hope that makes sense? Any idea why it does that?

 

Thanks heaps!

Sam.

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.