vaskovasilev Posted March 12, 2010 Share Posted March 12, 2010 Hello , I have one database with 6 same structure tables (only with different names). I want to put one dropdown menu to choose in wich table to insert the data . I have this code : <form action="" method="post"> <select name="dropdown"> <option>business</option> <option>design</option> <option >entertainment</option> <option >it</option> <option >lifestyle</option> <option >press</option> </select> <input class="input_text" type="text" name="name"> <input class="input_text" type="text" name="mail"> <input class="input_text" type="text" name="address"> <textarea class="input_textarea" name="comment"></textarea> <input type="submit" name="submit" value="Изпрати" class="button"> </form> <?php if (isset($_POST["submit"])) { $dbhost = "localhost"; $dbuser = ""; $dbpass = ""; $dbname = ""; $conn = mysql_connect($dbhost, $dbuser, $dbpass)or die(mysql_error()); mysql_select_db($dbname, $conn)or die(mysql_error()); if (!empty($_POST["name"])) $name = htmlspecialchars($_POST["name"]); else $errMsg = " <a class=maintext2><font color=#000000>please write name!</font></a><br />"; if (!empty($_POST["mail"])) $mail = htmlspecialchars($_POST["mail"]); else $errMsg = "<a class=maintext2><font color=#000000>please write e-mail!</font></a><br />"; if (!empty($_POST["address"])) $address = htmlspecialchars($_POST["address"]); else $errMsg = "<a class=maintext2><font color=#000000>please write address!</font></a><br />"; if (!empty($_POST["comment"])) $comment = htmlspecialchars($_POST["comment"]); else $errMsg = "<a class=maintext2><font color=#000000>please write message!</font></a><br />"; if (empty($errMsg)) { $insert = mysql_query("INSERT INTO $dropdown(name, mail , address , comment) VALUES('$name', '$mail', '$address', '$comment')")or die(mysql_error()); echo '<a class=maintext2><font color=#000000> message send!</font></a><br />'; } else echo $errMsg; mysql_close(); } ?> Can you help me with this code ? thank you Quote Link to comment https://forums.phpfreaks.com/topic/194996-dropdown-menu-for-select-different-table/ Share on other sites More sharing options...
rpmorrow Posted March 12, 2010 Share Posted March 12, 2010 Your query needs to use $_POST['dropdown'] instead of $dropdown Quote Link to comment https://forums.phpfreaks.com/topic/194996-dropdown-menu-for-select-different-table/#findComment-1025137 Share on other sites More sharing options...
vaskovasilev Posted March 12, 2010 Author Share Posted March 12, 2010 you want to say this : $insert = mysql_query("INSERT INTO $_POST['dropdown'] (name, mail , address , comment) VALUES('$name', '$mail', '$address', '$comment')")or die(mysql_error()); or not because now it says : Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/biznes/admin.php on line 73 .. the line where is $_POST Quote Link to comment https://forums.phpfreaks.com/topic/194996-dropdown-menu-for-select-different-table/#findComment-1025141 Share on other sites More sharing options...
vaskovasilev Posted March 12, 2010 Author Share Posted March 12, 2010 .. i made it with case switch ($_POST['dropdown']) { case "business": $insert = mysql_query("INSERT INTO table (name, mail , address , comment) VALUES('$name', '$mail', '$address', '$comment')")or die(mysql_error()); break; .... } so thank you for the idea Quote Link to comment https://forums.phpfreaks.com/topic/194996-dropdown-menu-for-select-different-table/#findComment-1025204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.