I want to select a mysql database table from a dropdown list to insert a new record in my database. How can I do that ?. in the picture below, I am using category to select a table in database. Thanks
我想从下拉列表中选择一个mysql数据库表,在我的数据库中插入一条新记录。我怎样才能做到这一点 ?。在下图中,我使用类别来选择数据库中的表。谢谢
1 个解决方案
#1
0
Just setup a value of this field corresponding name from database, for example:
只需在数据库中设置此字段对应名称的值,例如:
<select name="table_db">
<option value="user_table">Users</option>
</select>
Then in PHP script just use your $_POST['table_db'] to get name of table, but ofcourse you need to escape it before use:
然后在PHP脚本中使用$ _POST ['table_db']来获取表的名称,但是在使用之前你需要将其转义:
$table_name = $_POST['table_db']; //escape it here!!!
$query = "SELECT * FROM $table_name;";
That's all.
就这样。
#1
0
Just setup a value of this field corresponding name from database, for example:
只需在数据库中设置此字段对应名称的值,例如:
<select name="table_db">
<option value="user_table">Users</option>
</select>
Then in PHP script just use your $_POST['table_db'] to get name of table, but ofcourse you need to escape it before use:
然后在PHP脚本中使用$ _POST ['table_db']来获取表的名称,但是在使用之前你需要将其转义:
$table_name = $_POST['table_db']; //escape it here!!!
$query = "SELECT * FROM $table_name;";
That's all.
就这样。