# Connect to MySQL with variables

**URL:** <https://forum.kirupa.com/t/connect-to-mysql-with-variables/178290>\
**Category:** Uncategorized\
**Created:** [February 9, 2006, 5:11am UTC](https://forum.kirupa.com/t/connect-to-mysql-with-variables/178290 "2006-02-09T05:11:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbrollwitme](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@pbrollwitme](https://forum.kirupa.com/u/pbrollwitme)\
**Post date:** [February 9, 2006, 5:11am UTC](https://forum.kirupa.com/t/connect-to-mysql-with-variables/178290/1 "2006-02-09T05:11:49Z")

</div>

hey all,  
I’m having a problem that i didn’t know would be one. I’m trying to connect to a mySQL table determined by variables from an html form. Basically, I have an html form with a input box with the name “town”. On submit, the variables are passed to a php script as follows:

```php
<?php
$link = mysql_connect("localhost", "clients", "password");
mysql_select_db("$state", $link);
$result = mysql_query("SELECT name,category FROM $town WHERE (name='$name') AND (category='$category')");

```

as you can see i’m trying to connect to a specific state database, from which i will select the table specified with the $town variable. I’ve replaced $town with the actual town name to ensure that the table works and it does. So the problem comes when i try to use $town to denote the table i wish to open. I’ve also tried using ‘$town’ and (’$town’). Anyone have any suggestions???  
Thanks,  
Mat
