zed420 Posted June 16, 2008 Share Posted June 16, 2008 Hi All I wonder if you could help me I'm trying to write a programm for Full-text search but I can not seem to get the query right. error says it can not connect to databse. Here is my code <?php include("DB.php"); // If the form has been submitted with supplied keywords if (isset($_POST['keywords'])) { // Connect to server and select database $keywords = $_POST['keywords']; // Create the query $query= "SELECT ItemName FROM itemtb WHERE MATCH(ItemName) against(`$keywords`)"; $result = mysql_query($query) or die ("Couldn't execute query for collecting your data."); ?> <TABLE BORDER=0 WIDTH=90% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#99CC99"> <TR ALIGN=CENTER bgcolor="#CCFF66"> <td><font color=red><b>Item name</font></TD> </tr> <? while ($row = mysql_fetch_array($result)) { extract($row); echo "<tr align=center> <td>" . $row['ItemName'] . "</td> </tr>"; } ?></table><? } ?> <p> <form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>"> Keywords:<br /> <input type="text" name="keywords" size="20" maxlength="40" value="" /><br /> <input type="submit" value="Search!"> </form> </p> If I leave the last two bits off (MATCH() AGAINST()) it connect to databse. Any suggestions Zed Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/ Share on other sites More sharing options...
DyslexicDog Posted June 16, 2008 Share Posted June 16, 2008 The problem is most likely in your DB.php file please put that code up too. Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-566580 Share on other sites More sharing options...
DarkWater Posted June 16, 2008 Share Posted June 16, 2008 Okay, two things. 1) Show us DB.php. 2) Why do you have "box" characters in that script? Which editor are you using? Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-566582 Share on other sites More sharing options...
zed420 Posted June 16, 2008 Author Share Posted June 16, 2008 here is the DB code <?php $database = "sampledb"; $user = "xxxxxxxx"; $pass = "xxxxxx"; $hostname = "localhost"; $table = "itemtb"; $db = mysql_connect("$hostname", "$user","$pass"); mysql_select_db("$database"); ?> On same script if I use different query it works fine for example if I take off MATCH and AGAINST and just leave it to show all ItemName it works. I'm using Dreamweaver. thanks for looking at my post Zed Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-566585 Share on other sites More sharing options...
DyslexicDog Posted June 17, 2008 Share Posted June 17, 2008 Try this, please report errors. <?php include("DB.php"); // If the form has been submitted with supplied keywords if (isset($_POST['keywords'])) { // Connect to server and select database $keywords = $_POST['keywords']; $keywords = mysql_real_escape_string($keywords); // Create the query $query= "SELECT ItemName FROM itemtb WHERE MATCH(ItemName) against(`$keywords`)"; $result = mysql_query($query) or die (mysql_errno() .":". mysql_error()); ?> <TABLE BORDER=0 WIDTH=90% CELLSPACING=3 CELLPADDING=3 ALIGN=CENTER bgcolor="#99CC99"> <TR ALIGN=CENTER bgcolor="#CCFF66"> <td><font color=red><b>Item name</font></TD> </tr> <? while ($row = mysql_fetch_array($result)) { extract($row); echo "<tr align=center> <td>" . $row['ItemName'] . "</td> </tr>"; } ?></table><? } ?> <p> <form name="action" id="action" method="post" action="<?=$_SERVER['PHP_SELF']?>"> Keywords:<br /> <input type="text" name="keywords" size="20" maxlength="40" value="" /><br /> <input type="submit" value="Search!"> </form> </p> Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-566936 Share on other sites More sharing options...
hitman6003 Posted June 17, 2008 Share Posted June 17, 2008 Are you using a MyISAM table with a fulltext index on the column(s) you are trying to query against? Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-566938 Share on other sites More sharing options...
zed420 Posted June 17, 2008 Author Share Posted June 17, 2008 Thanks for replying hitman yes I'm using fulltext index on ItmName. DyslexicDog I've tried your query it brought me this Error; 1054:Unknown column 'm' in 'where clause' 'm' is the word I put in for search. thanks Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-567234 Share on other sites More sharing options...
conker87 Posted June 17, 2008 Share Posted June 17, 2008 Use apostrophes not back quotes for strings. $query= "SELECT ItemName FROM itemtb WHERE MATCH(ItemName) against('$keywords')"; Also, for the love of God, use full tags <?php ?> not <? ?> Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-567241 Share on other sites More sharing options...
zed420 Posted June 17, 2008 Author Share Posted June 17, 2008 Thanks conker you got me very close I'm not getting any result as yet but there are NO errors any more. I think I'm getting closer... Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-567256 Share on other sites More sharing options...
conker87 Posted June 17, 2008 Share Posted June 17, 2008 There doesn't seem to be anything wrong with your code, I'm dumbfounded. Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-567263 Share on other sites More sharing options...
zed420 Posted June 17, 2008 Author Share Posted June 17, 2008 Thanks blue much appreciated. Zed Quote Link to comment https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-567267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.