yobo Posted March 5, 2007 Share Posted March 5, 2007 hey all, i was wondering how would i do this, lets say i had a database with a table called admin hacks and another table called user hacks, and both tables had feilds called name and id now what i want to be able to do is create a submit form with a drop down menu saying the table names mentiond above, also the form will have a field called name. now lets say a user slected admin hacks from the drop down menu and enterd jack in the name, how would i get the data in that submitted form to be inserted into the correct database table, so jack should now be in the table called admin hacks also lets say someone selected user hacks and entered jon how would i do the same for that? sorry if it sounds confusing Link to comment https://forums.phpfreaks.com/topic/41301-add-data-to-a-database-using-dropdown-menus/ Share on other sites More sharing options...
boo_lolly Posted March 5, 2007 Share Posted March 5, 2007 that wouldn't be too difficult. something like: <?php if(isset($_POST)){ $sql = "INSERT INTO ". $_POST['table_name'] ." (name) VALUES (". $_POST['name'] .")"; msyql_query($sql); } echo "<form action=\"\" method=\"post\">\n"; echo "<select name=\"table_name\">\n"; echo "<option value=\"admin_hacks\">Admin Hacks\n"; echo "<option value=\"user_hacks\">User Hacks\n"; echo "</select>\n"; echo "Enter name: <input type\"text\" name=\"name\">\n"; echo "<input type=\"submit\" value=\"Submit\">\n"; echo "</form>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/41301-add-data-to-a-database-using-dropdown-menus/#findComment-200120 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.