Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/110418-full-text-search/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-566585
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/110418-full-text-search/#findComment-566936
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.