0

ユーザーにmysqlデータベースのテーブル名を選択してもらい、フィールド内のフォームのテキストボックスでデータを追加できます。PHP $_POST[ ] を使用して、追加フォームにテーブル名を送信しました。ただし、追加形式で。追加ボタンを送信したとき; テーブル名が失われました。テーブル名の値を保持するために、多くを検索し、セッションと定数をテストしました。しかし、望ましい結果が得られませんでした。

どんな助けでも大歓迎です。

テーブル名を選択するページのコードは次のとおりです。

<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>

そして、これが「change_products.php」ページの追加フォームのコードです。

<?
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>
4

1 に答える 1