title: Querying a mySQL Database with php. How to Set WHERE to a php var
body: <p>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...</p>
  
  <pre><code>$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); 
  </code></pre>
  
  <p>The above code works, but only for searching by ID. How would I get it to look something like this..</p>
  
  <pre><code>$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); 
  </code></pre>
  
  <p>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?</p>