Jump to content

Drop down Menu expands to textfield (Insert into MySQL)


wispas

Recommended Posts

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

} ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.