Hi, i have 2 tables in a database, both tables are identical exept for the name
i have a form in a html file, it feeds the data to a php file that connect to the database and inserts the data in one of the tables.
i want the users to choose which table in the database to submit the data to, therefore i added a dropdown menu with the names of the 2 tables in the form.
now the part im strugling with, i need a code to add into the php so that the line;
[COLOR=”Lime”]INSERT INTO table1
becomes like this
[COLOR=”lime”]INSERT INTO {$table_chosen}[COLOR=”Silver”]//$table_choosen will become the value selected by the user from the form drop down menu.
this is my html code
[code=html]
<table border=”1″ width=”36%”>
<tr>
<td valign=”top” width=”109″>Album Name</td>
<td valign=”top”>
<form method=”POST” action=”insert.php”>
<input type=”text” name=”album_name” size=”32″></td>
</td>
</tr>
<tr>
<td width=”109″>Artist</td>
<td><input type=”text” name=”album_artist” size=”32″></td>
</tr>
<tr>
<td width=”109″>Screenshot Url</td>
<td><input type=”text” name=”album_ssurl” size=”32″></td>
</tr>
<tr>
<td width=”109″>Latin Unit</td>
<td><input type=”text” name=”album_mirror0″ size=”32″></td>
</tr>
<tr>
<td width=”109″>Rapid Share</td>
<td><input type=”text” name=”album_mirror1″ size=”32″></td>
</tr>
<tr>
<td width=”109″>Deposit Files</td>
<td><input type=”text” name=”album_mirror2″ size=”32″></td>
</tr>
<tr>
<td width=”109″>Torrent</td>
<td><input type=”text” name=”album_mirror3″ size=”32″></td>
</tr>
<tr>
<td width=”109″>Category</td>
<td>
<p><select size=”1″ name=”album_tables”>
<option selected value=”albums_country”>Country</option>
<option value=”albums_alternative”>Alternative</option>
</select></p>
</td>
</tr>
<tr>
<td colspan=”2″ valign=”middle”>
<p align=”center”>
<input type=”submit” value=”Submit” name=”B1″><input type=”reset” value=”Reset” name=”B2″>
</form>
</td>
</tr>
</table>
and this is my php file
[code=php]
<?php
$con = mysql_connect(“mysql1034.domain.net”,”albums”,”password”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“albunes”, $con);
$sql=”INSERT INTO albums_country (album_name, album_artist, album_ssurl, album_mirror0, album_mirror1, album_mirror2, album_mirror3)
VALUES
(‘$_POST[album_name]’,’$_POST[album_artist]’,’$_POST[album_ssurl]’,’$_POST[album_mirror0]’,’$_POST[album_mirror1]’,’$_POST[album_mirror2]’,’$_POST[album_mirror3]’)”;
if (!mysql_query($sql,$con))
{
die(‘Error: ‘ . mysql_error());
}
echo “1 added!”;
mysql_close($con)
?>