title: How to insert a field of data in mysql from another table, based from user input from a form?
body: <p>I am developing a system in which people can be added to a database using mysql and php.
  The basis of my form is that an administrator can add person-types and person-roles, and these are applied to the user when their details are entered in the form. For example, if this system was applied to a school environment the person type could be a teacher, or a cook, and the person role could be a parent, for the person type does not exclude the person role. I have had various problems with this system for that the foreign keys don't update as my system uses MYISAM type tables, but if I use INNODB tables my data entry will not work. I am seeking ways in which I can use queries for the meantime to get this working as it is for a university project, and my deadline is ever looming. However I do mean to get this system working, so will seek ways to get it fully functioning  a bit later in the year.
  I have javascript in place for error handling, and php blocks of code to help prevent against sql injection attacks.</p>
  
  <p>When an administrator is entering a user, there is a drop down menu which is populated by the fields in the person type table, this is done by the  <strong>Person_Type_Value_Description</strong> field in the person-type table.  Each row in the person type table would have an <strong>Person_Type_ID</strong>. I need a query that can find the <strong>Person_Type_Value_Description</strong>, call the <strong>Person_Type_ID</strong> and store it in a variable so that it can be parsed through to the person type id in the person table. The basic layout of my tables can be seen below from the creation scripts.</p>
  
  <pre><code>CREATE TABLE Person_Type(
  Person_Type_ID int auto_increment NOT NULL,
  Person_Type_Value_Description varchar(150) NOT NULL,
  Create_Date datetime NOT NULL NOT NULL,
  Modify_Date datetime NOT NULL  NOT NULL,
  Archive char(1) NULL,
  CONSTRAINT PK_Person_Type_ID PRIMARY KEY (Person_Type_ID)
   ) ;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>CREATE TABLE Person(
  Person_ID int auto_increment NOT NULL,
  Person_Type_ID int NOT NULL,
  Create_Date datetime NOT NULL ,
  Modify_Date datetime NOT NULL ,
  First_Name varchar(50) NOT NULL,
  Surname varchar(50) NOT NULL,
  DOB date NOT NULL,
  Gender char(1) NOT NULL CHECK (Gender ='f' OR Gender ='m'),
  Archive char(1) NULL,
  Allergies varchar(200) NOT NULL,
  Dietry_Requirements varchar(200) NOT NULL,
  Disabilities varchar(200) NOT NULL,
  Medicine_Requirements varchar(200) NOT NULL,
  username varchar (30) NOT NULL,
  password varchar (30) NOT NULL,
  CONSTRAINT PK_Person_ID PRIMARY KEY (Person_ID),
  CONSTRAINT FK_Person_Type_ID FOREIGN KEY (Person_Type_ID)
  REFERENCES Person_Type (Person_Type_ID)) ;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Below is the code I have tried to get working.
  I need to store the result of the query so I can parse it to the Person table through an insert command. Thank you for commenting.</p>
  
  <p>The problem I am having is that the <strong>Person_Type_ID</strong> in the Person table is always setting to 0, because of the NOT NULL command, however it is not updating based off my queries.</p>
  
  <pre><code>// drawing the information from the Person_Type table.
  $sql9 = "(SELECT Person_Type_ID
                   FROM Person_Type pt
                  WHERE pt.Person_Type_Value_Description =  $Person_Type_Value_Description)";
                  $result = @mysql_query($sql9);
  
  //inserting into the person table. **All filed work except for the Person_Type_ID
  $qry = "INSERT INTO Person (Person_Type_ID, Create_Date, Modify_Date, First_Name, Surname, DOB, Gender, Allergies, Dietry_Requirements, Disabilities, Medicine_Requirements, username, password) 
     VALUES('$sql9', NOW(), NOW(), '$First_Name', '$Surname', '$DOB', '$Gender', '$Allergies', '$Dietry_Requirements', '$Disabilities', '$Medicine_Requirements', '$username', '$password')" ;
      $result = @mysql_query($qry);
  </code></pre>
  
  <p><strong>How it is called to display in the form</strong></p>
  
  <pre><code>&lt;?
  
  $persontype = array();
  
  $qry = mysql_query("SELECT Person_Type_Value_Description FROM Person_Type ORDER BY Person_Type_ID");
  
  while($res = mysql_fetch_array($qry)) {
  $persontype[$res['Person_Type_Value_Description']] = $res['Person_Type_Value_Description'];
  }
  
  ?&gt; 
  
  
  //creates the drop down
  &lt;?
  function createDropdown($arr, $frm) {
  foreach ($arr as $key =&gt; $value) {
  echo '&lt;option value="'.$value.'"&gt;'.$value.'&lt;/option&gt;';
  }
  echo '&lt;/select&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>The administrator would then select this from a simple drop down menu.</p>
  
  <pre><code>&lt;td align="right"&gt;&lt;div align="left"&gt;Person Type* &lt;/div&gt;&lt;/td&gt;           
  &lt;td&gt;&lt;select name="Person_Type_Value_Description" id="Person_Type_Value_Description"&gt;
   &lt;option value=""&gt;Select One...&lt;/option&gt;
  &lt;?php createDropdown($persontype, 'frmpersontype'); ?&gt;
    &lt;/select&gt;
        &lt;/td&gt;
          &lt;/tr&gt; 
  </code></pre>