I'm building a live search feature on my site and I need to pass a model number variable so the PHP file knows which table to search.
Here are the form fields:
<form class="form-horizontal" name="search" role="form" method="POST" onkeypress="return event.keyCode != 13;">
<?php
$modelnumber = $_SERVER['REQUEST_URI']; 
$modelwithoutex = basename($modelnumber,".php");
$modelwithex = basename($modelnumber);
echo '<input id="modelmfp" name="modelmfp" type="text" value="'.$modelwithoutex.'">';
?>
<input id="name" name="name" type="text" class="form-control " placeholder="Search by error..." autocomplete="off"/>
</form>
Here's the Jquery
$(".tablesearch").hide();
// Search
function search() {
    var query_value = $('input#name').val();
    var query_modelmfp = $('input#modelmfp').val();
    console.log(query_modelmfp);
    console.log(query_value);
if(query_value !== ''){
    $.ajax({
        type: "POST",
        url: "php/search.php",
        data: { query: query_value, query2: query_modelmfp },
        cache: false,
        success: function(html){
            $("table#resultTable tbody").html(html);
        }
    });
    }return false;    
}
Here's the PHP file
$search_string = preg_replace("/[^A-Za-z0-9]/", " ", $_POST['query']);
$themodelmfp = $_POST['query2'];
$search_string = $test_db->real_escape_string($search_string);
$themodelmfp = $test_db->real_escape_string($themodelmfp);
$query = 'SELECT * FROM '.$themodelmfp.' WHERE code LIKE "%'.$search_string.'%"';
Console Log
jquery.min.js:4 POST http://url/search.php 500 (Internal Server Error)
Why isn't the $themodelmfp variable passing? If I manually type the model number it works fine.
The search string passing without any issues.
Any help would be greatly appreciated.
Thanks,
