So I am working on search engine for mySQL database on a website. And I Want the user to be able to select how they are going to be searching. Like so...
$searchBy=mysqli_real_escape_string($conn, $_POST['recordType']); 
$searchText=mysqli_real_escape_string($conn, $_POST['searchText']); 
$getRecordsSQL = "SELECT * FROM weighs WHERE ID='$searchText'"; 
$recordsQuery = mysqli_query($conn,$getRecordsSQL); 
The above code works, but only for searching by ID. How would I get it to look something like this..
$searchBy=mysqli_real_escape_string($conn, $_POST['recordType']); 
$searchText=mysqli_real_escape_string($conn, $_POST['searchText']); 
$getRecordsSQL = "SELECT * FROM weighs WHERE '$searchBy'='$searchText'"; 
$recordsQuery = mysqli_query($conn,$getRecordsSQL); 
That code does not work, but you get the point. Is there a way to format that query so the user can pick the column they would like to look at, Aka WHERE?
 
    