Jump to content

add data to a database using dropdown menus?


yobo

Recommended Posts

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

 

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";
?>
        

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.