I want the user choose a table name in mysql database and then I can add a data by textbox of a form inside the field. I used PHP $_POST[ ] to send table name to the adding form. but in the adding form; when I submit the add button; the table name has been lost. I have searched a lot and tested session and constant to hold the table name value; but didn't get the desired result.
Any help will be greatly appreciated.
here is the code of the page which selecting the table name:
<form action="change_products.php" method="post" name="select_table">
<select name="edit_products" >
<option <?php if($_POST['edit_products'] == "cabin") echo "selected='selected'"; ?> value="cabin">Cabin case</option>
<option <?php if($_POST['edit_products'] == "cabin_door") echo "selected='selected'"; ?> value="cabin_door">Cabin door</option>
</select>
<input type="submit" value="OK">
</form>
and this is the code of the adding form in "change_products.php" page.
<?
include('functions.php'); //the database info
define('selected_table', $_POST['edit_products']);
?>
<form method="post">
<table>
<tr>
<td>Mark:</td>
<td><input type="text" name="mark" /></td>
</tr>
<tr>
<td><input type="submit" name="add" value="New" /></td>
</tr>
</table>
<?
if (isset($_POST['add']))
{
$mark=$_POST['mark'];
mysql_query("INSERT INTO ".selected_table." (mark) VALUES ('$mark')");
}
?>
</form>