forumnz Posted January 24, 2008 Share Posted January 24, 2008 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 More sharing options...
cooldude832 Posted January 24, 2008 Share Posted January 24, 2008 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 https://forums.phpfreaks.com/topic/87498-please-help-regarding-syntax-error/#findComment-447543 Share on other sites More sharing options...
kenrbnsn Posted January 24, 2008 Share Posted January 24, 2008 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 https://forums.phpfreaks.com/topic/87498-please-help-regarding-syntax-error/#findComment-447545 Share on other sites More sharing options...
forumnz Posted January 24, 2008 Author Share Posted January 24, 2008 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 https://forums.phpfreaks.com/topic/87498-please-help-regarding-syntax-error/#findComment-447549 Share on other sites More sharing options...
kenrbnsn Posted January 24, 2008 Share Posted January 24, 2008 Please show us the code you're using. Ken Link to comment https://forums.phpfreaks.com/topic/87498-please-help-regarding-syntax-error/#findComment-447769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.