Unable to get results of external database query

Permalink
Hi everyone,

I'm apparently unable to get the value from an html form via method="POST" to be passed to the controller for my single page. The goal here is to get the input from the user through the form and pass it to the results page, where the input is used as a search query to an external MySQL database and the results of the search get displayed.

Here's the code for the page with the form:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>  
<div class="searchForm">
   <form style="text-align:center;" method="post" action="<?php echo $this->action('db_search'); ?>" >
      <input  type="text" id="search_input">
      <input  type="submit" id="submit" value="Search">
   </form>
</div>

And here's the code in the controller for the search results page:
<?php 
   defined('C5_EXECUTE') or die("Access Denied.");
   class BinderSearchController extends Controller {
      public function binder_search() {
         if(isset( $_POST['submit'])) {
            $input = trim($_POST['submit']); //Remove any extra space
            $input = mysqli_real_escape_string($input); //Some validation
            // Load MySQL database
            $db = Loader::db( 'localhost', 'username', 'password', 'mydb', true);
            // Get a list of all column names in the table
            $columnquery = "SELECT column_name FROM information_schema.columns WHERE table_name = 'mytable'";
            $names = $db->Execute($columnquery);
            //Submit query to MYSQL database and get results
            $query = "SELECT * FROM mytable WHERE MATCH(".$names.") AGAINST(".$input.")";
            $r = $db->Execute($query);

I only ever get the "Something's not working!" message on the results page, which means that $_POST isn't getting the value 'submit' from the form, and I can't figure out why for the life of me. If anyone can help me figure this out I'd really appreciate it!

 
rhuffman8 replied on at Permalink Reply
rhuffman8
I don't know if this is still an issue but I've been playing around with similar things recently and found that the MATCH() AGAINST() in mySQL cannot be used unless you make some changes to the table settings because the current setup does not support fulltext indexing. Though it doesn't run as fast,
SELECT field FROM table WHERE column LIKE "%search%";

has been returning the desired results for me.

I'm sure this doesn't solve the apparent issue with the $_POST not working properly but it might be something to play around with, if you haven't already.
Mnkras replied on at Permalink Reply
Mnkras
you are using

$this->action('db_search');


but your function name is binder_search,

choose one or the other, (db_search or binder_search)