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
https://forums.phpfreaks.com/topic/87498-please-help-regarding-syntax-error/
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

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

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.

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.