Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Query error (PHP)
    primarykey
    data
    text
    <p>Having some issues with this search engine I am trying to put together. I'll provide everything to make things easier. I'm a Web Designer and don't usually play around with MySQL so I'm quite sure I am missing something obvious here. I get this error whenever I try to search:</p> <blockquote> <p>Error performing query SELECT firstname, lastname, comments FROM test WHERE MATCH (firstname, lastname, comments) AGAINST ('ash')</p> </blockquote> <p>Thanks</p> <p><strong>PHP file (mysql.php)</strong></p> <pre><code>&lt;?php // define 'MySQL' class class MySQL{ private $conId; private $host; private $user; private $password; private $database; private $result; const OPTIONS=4; public function __construct($options=array()){ if(count($options)!=self::OPTIONS){ throw new Exception('Invalid number of connection parameters'); } foreach($options as $parameter=&gt;$value){ if(!$value){ throw new Exception('Invalid parameter '.$parameter); } $this-&gt;{$parameter}=$value; } $this-&gt;connectDB(); } // connect to MySQL private function connectDB(){ if(!$this-&gt;conId=mysql_connect($this-&gt;host,$this-&gt;user,$this-&gt;password)){ throw new Exception('Error connecting to the server'); } if(!mysql_select_db($this-&gt;database,$this-&gt;conId)){ throw new Exception('Error selecting database'); } } // run query public function query($query){ if(!$this-&gt;result=mysql_query($query,$this-&gt;conId)){ throw new Exception('Error performing query '.$query); } return new Result($this,$this-&gt;result); } public function escapeString($value){ return mysql_escape_string($value); } } // define 'Result' class class Result { private $mysql; private $result; public function __construct(&amp;$mysql,$result){ $this-&gt;mysql=&amp;$mysql; $this-&gt;result=$result; } // fetch row public function fetchRow(){ return mysql_fetch_assoc($this-&gt;result); } // count rows public function countRows(){ if(!$rows=mysql_num_rows($this-&gt;result)){ return false; } return $rows; } // count affected rows public function countAffectedRows(){ if(!$rows=mysql_affected_rows($this-&gt;mysql-&gt;conId)){ throw new Exception('Error counting affected rows'); } return $rows; } // get ID form last-inserted row public function getInsertID(){ if(!$id=mysql_insert_id($this-&gt;mysql-&gt;conId)){ throw new Exception('Error getting ID'); } return $id; } // seek row public function seekRow($row=0){ if(!is_int($row)||$row&lt;0){ throw new Exception('Invalid result set offset'); } if(!mysql_data_seek($this-&gt;result,$row)){ throw new Exception('Error seeking data'); } } } ?&gt; </code></pre> <p><strong>PHP file (processform.php)</strong></p> <pre><code>&lt;?php // include MySQL-processing classes require_once 'mysql.php'; try{ // connect to MySQL $db=new MySQL(array ('host'=&gt;'localhost','user'=&gt;'xxx','password'=&gt;'xxx','database'=&gt;'xxx')); $searchterm=$db-&gt;escapeString($_GET['searchterm']); $result=$db-&gt;query("SELECT firstname, lastname, comments FROM test WHERE MATCH (firstname, lastname, comments) AGAINST ('$searchterm')"); if(!$result-&gt;countRows()){ echo '&lt;div class="maincontainer"&gt;&lt;h2&gt;No results were found. Go back and try a new search.&lt;/h2&gt;&lt;/div&gt;'."n"; } else{ // display search results echo '&lt;div class="maincontainer"&gt;&lt;h2&gt;Your search criteria returned '.$result-&gt;countRows().' results.&lt;/h2&gt;'."n"; while($row=$result-&gt;fetchRow()){ echo '&lt;div class="rowcontainer"&gt;&lt;p&gt;&lt;strong&gt;First Name: &lt;/strong&gt;'.$row['firstname'].'&lt;p&gt;&lt;p&gt;&lt;strong&gt;Last Name: &lt;/strong&gt;'.$row['lastname'].'&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Comments: &lt;/strong&gt;'.$row['comments'].'&lt;/p&gt;&lt;/div&gt;'."n"; } } echo '&lt;/div&gt;'; } catch(Exception $e){ echo $e-&gt;getMessage(); exit(); } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload