0

Ok, so I have a variable $city and it passes a value from the submit form as "New York" when this happens, I want to do a query in a table name that matches the $city value. in this case New York.

The table name would be New_York

Form page For example: What city do you need?: $city Submit

Results page

$city=$_POST['city'];
$sql = $db->query(Select * from $city);

(where $city should be the name of the table)

How do I accomplish this?

Keep in mind my city list has names that use spaces whereas table names cant.

1 Answers1

0

You could try to replace spaces with underscores using str_replace

$city = str_replace(' ', '_',$_POST['city']);
$sql = $db->query("SELECT * FROM {$city}");

***please note this code is prone to sql attacks*

Adam Hull
  • 214
  • 1
  • 8