wispas Posted January 19, 2010 Share Posted January 19, 2010 This is simply inserting the form data into the mysql database. so i have a database field with the name 'licence'. this determines the persons licence type.... i have a drop down menu (name is licence which inserts teh value into the database) this drop down menu has the option to select a other option which opens up a text field.... does anyone know how i can script it so that when the user fills in the text field it will go into the database as the text field value rather than the value of other which is taken from the drop down menu. Heres the form: <form id="form1" name="form1" method="post" action="thank_you.php"> <table width="580" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td colspan="2" align="left" valign="top"><h1>New Agency Application</h1></td> <td width="215" rowspan="4" align="right" valign="top"> </td> </tr> <tr> <td width="130" align="right" valign="top">Agency Name:</td> <td width="215" align="left" valign="top"><label> <input type="text" name="agency_name" id="agency_name" /> </label></td> </tr> <tr> <td align="right" valign="top">Title:</td> <td align="left" valign="top"><label> <select name="title" id="title"> <option value="" selected="selected"></option> <option value="Mr">Mr</option> <option value="Mrs">Mrs</option> <option value="Miss">Miss</option> <option value="Ms">Ms</option> <option value="Sir">Sir</option> <option value="Dr">Dr</option> </select> </label></td> </tr> <tr> <td align="right" valign="top">Forename:</td> <td align="left" valign="top"><label> <input type="text" name="forename" id="forename" /> </label></td> </tr> <tr> <td align="right" valign="top">Lastname:</td> <td colspan="2" align="left" valign="top"><label> <input type="text" name="lastname" id="lastname" /> </label></td> </tr> <tr> <td align="right" valign="top">Address:</td> <td colspan="2" align="left" valign="top"><label> <textarea name="address" id="address" cols="45" rows="5"></textarea> </label></td> </tr> <tr> <td align="right" valign="top">Phone Number:</td> <td colspan="2" align="left" valign="top"><label> <input type="text" name="phone_no" id="phone_no" /> </label></td> </tr> <tr> <td align="right" valign="top">Email Address:</td> <td colspan="2" align="left" valign="top"><label> <input type="text" name="email_add" id="email_add" /> </label></td> </tr> <tr> <td align="right" valign="top">Licence Type:</td> <td colspan="2" align="left" valign="top"><label> <select name="licence"> <option value="" selected="selected"></option> <option value="ABTA">ABTA</option> <option value="ATOL">ATOL</option> </select> </label></td> </tr> <tr> <td align="right" valign="top">Licence Number:</td> <td colspan="2" align="left" valign="top"><input type="text" name="licence_number" id="licence_number" /></td> </tr> <tr> <td align="right" valign="top"> </td> <td colspan="2" align="left" valign="top"><label> <input type="submit" name="submit" id="submit" value="Register" /> </label></td> </tr> </table> </form> Heres the PHP Generator that inserts that data into the mysql database: <?php include('includes/connectdb.php'); $tbl_name="agents_list"; // Table name if(isset($_POST['submit'])) { $agency_name = $_POST['agency_name']; $title = $_POST['title']; $forename = $_POST['forename']; $lastname = $_POST['lastname']; $address = $_POST['address']; $phone_no = $_POST['phone_no']; $email_add = $_POST['email_add']; $licence = $_POST['licence']; $licence_number = $_POST['licence_number']; // Insert data into mysql $sql="INSERT INTO $tbl_name(agency_name, title, forename, lastname, address, phone_no, email_add, licence, licence_number, CD, UD)VALUES('$agency_name', '$title', '$forename', '$lastname', '$address', '$phone_no', '$email_add', '$licence', '$licence_number', curdate(), curdate())"; $result=mysql_query($sql); } else { echo "Failed to insert."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189012-drop-down-menu-expands-to-textfield-insert-into-mysql/ Share on other sites More sharing options...
fenway Posted January 20, 2010 Share Posted January 20, 2010 This is a php question -- just choose other first. Quote Link to comment https://forums.phpfreaks.com/topic/189012-drop-down-menu-expands-to-textfield-insert-into-mysql/#findComment-998453 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.