I have a database with four tables and I want my PHP to execute the query dynamically for one of these tables, based on the user's input.
$company = $_POST['company'];
$model = $_POST['model'];
$servername = "localhost";
$username = "user";
$password = "pass";
$database = "ref";
if ($company == "ford") {
$table = "ref_ford";
} else if ($company = "hyundai") {
$table == "ref_hyundai";
} else if ($company = "renault") {
$table == "ref_renault";
} else {
$table = "ref_fiat";
}
With this code, PHP doesn´t recognize the table, as when I selected it manually
$table = "ref_ford"
it does the query correctly.
I´ve also tried several different comparisons, both ==
and ===
, as well as,
$company == $_POST["ford"]
Any idea on how can I select the table based on the user's input?
<select name="company">
<option value = "ford">Ford</option>
<option value = "hyundai">Hyundai</option>
<option value = "renault">Renault</option>
<option value = "fiat">Fiat</option>
</select>