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:
And here's the code in the controller for the search results page:
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!
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:
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);
Viewing 15 lines of 31 lines. View entire code block.
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!
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.