Skip to main content
Inspiring
November 15, 2011
Question

sending different table id's into user table using a form

  • November 15, 2011
  • 1 reply
  • 10098 views

hello, this is a lead up to another discussion that has not been resolved. i am getting pretty desperate now. i am sure it cant be that hard and really need help i am using MySQL php

i have created a input form that when submitted sends the data to 3 different tables

i have a tenant table. guarantor table and landlord table all in the database. i also have a property table that is already populated by another form on the website. on the input form though the property table is a dynamic drop down menu that when selected populates fields on the top of the input form

i have the understanding that because the guarantorID, landlordID and propertyID are all inputting new data these will be input commands, however the property is already in the table so this will be an update command?

what i need to do is when the form is submitted the guarantorID, landlordID and propertyID all are sent to columns in the tenant table. this is called join i believe?

i have provided the unformatted code below that all works, but what i need to know how to do is the above. Link them all togeather and send all the id from the  guarantorID, landlordID and propertyID to the tenant table so they can all be reference when i create new pages

can this be done?

<?php require_once('Connections/nameprop.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;   

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

$editFormAction = $_SERVER['PHP_SELF'];

if (isset($_SERVER['QUERY_STRING'])) {

  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO name_tenant (Title, `First Names`, Surname, DOB, DOBMonth, DOBYear, Nationality, Marital_Status, DayNumber, EvenNumber, MobNumber, Smoker, CurrentAdd, Status, PreviousAdd, Student, FinancialCCj, FinancialArrears, FinancialBankR, FinancialNone, BankName, AccountNum, SortCode, BankDuration, DebitCCCard, Electoral, `next of kin`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                       GetSQLValueString($_POST['Title'], "text"),

                       GetSQLValueString($_POST['First_Names'], "text"),

                       GetSQLValueString($_POST['Surname'], "text"),

                       GetSQLValueString($_POST['DOB'], "text"),

                       GetSQLValueString($_POST['DOBMonth'], "text"),

                       GetSQLValueString($_POST['DOBYear'], "text"),

                       GetSQLValueString($_POST['Nationality'], "text"),

                       GetSQLValueString($_POST['Marital_Status'], "text"),

                       GetSQLValueString($_POST['DayNumber'], "double"),

                       GetSQLValueString($_POST['EvenNumber'], "double"),

                       GetSQLValueString($_POST['MobNumber'], "double"),

                       GetSQLValueString($_POST['Smoker'], "text"),

                       GetSQLValueString($_POST['CurrentAdd'], "text"),

                       GetSQLValueString($_POST['Status'], "text"),

                       GetSQLValueString($_POST['PreviousAdd'], "text"),

                       GetSQLValueString($_POST['Student'], "text"),

                       GetSQLValueString($_POST['FinancialCCj'], "text"),

                       GetSQLValueString($_POST['FinancialArrears'], "text"),

                       GetSQLValueString($_POST['FinancialBankR'], "text"),

                       GetSQLValueString($_POST['FinancialNone'], "text"),

                       GetSQLValueString($_POST['BankName'], "text"),

                       GetSQLValueString($_POST['AccountNum'], "double"),

                       GetSQLValueString($_POST['SortCode'], "double"),

                       GetSQLValueString($_POST['BankDuration'], "text"),

                       GetSQLValueString($_POST['DebitCCCard'], "text"),

                       GetSQLValueString($_POST['Electoral'], "text"),

                       GetSQLValueString($_POST['next_of_kin'], "text"));

  mysql_select_db($database_nameprop, $nameprop);

  $Result1 = mysql_query($insertSQL, $nameprop) or die(mysql_error());

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO name_guarantor (FullName, Title, DOBday, DOBMonth, DOBYear, Sex, MaritalStatus, DaytimeNumber, EveningNumber, MobileNumber, Email, CurrentAddress, PreviousAddress, BankName, AccountNum, SortCode, BankDuration, CCDebitCard, ElectoralRoll, Profession, AnnualWages, PayrollNum, EmpName, EmpAddress, EmpContName, EmpContNumber, EmpEmail, EmpFinaHist, EmpDate, EmpDisclaimer) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",

                       GetSQLValueString($_POST['FullName'], "text"),

                       GetSQLValueString($_POST['Title'], "text"),

                       GetSQLValueString($_POST['DOBday'], "double"),

                       GetSQLValueString($_POST['DOBMonth'], "text"),

                       GetSQLValueString($_POST['DOBYear'], "text"),

                       GetSQLValueString($_POST['Sex'], "text"),

                       GetSQLValueString($_POST['MaritalStatus'], "text"),

                       GetSQLValueString($_POST['DaytimeNumber'], "double"),

                       GetSQLValueString($_POST['EveningNumber'], "double"),

                       GetSQLValueString($_POST['MobileNumber'], "double"),

                       GetSQLValueString($_POST['Email'], "text"),

                       GetSQLValueString($_POST['CurrentAddress'], "text"),

                       GetSQLValueString($_POST['PreviousAddress'], "text"),

                       GetSQLValueString($_POST['BankName'], "text"),

                       GetSQLValueString($_POST['AccountNum'], "double"),

                       GetSQLValueString($_POST['SortCode'], "double"),

                       GetSQLValueString($_POST['BankDuration'], "text"),

                       GetSQLValueString($_POST['CCDebitCard'], "text"),

                       GetSQLValueString($_POST['ElectoralRoll'], "text"),

                       GetSQLValueString($_POST['Profession'], "text"),

                       GetSQLValueString($_POST['AnnualWages'], "text"),

                       GetSQLValueString($_POST['PayrollNum'], "double"),

                       GetSQLValueString($_POST['EmpName'], "text"),

                       GetSQLValueString($_POST['EmpAddress'], "text"),

                       GetSQLValueString($_POST['EmpContName'], "text"),

                       GetSQLValueString($_POST['EmpContNumber'], "double"),

                       GetSQLValueString($_POST['EmpEmail'], "text"),

                       GetSQLValueString($_POST['EmpFinaHist'], "text"),

                       GetSQLValueString($_POST['EmpDate'], "double"),

                       GetSQLValueString($_POST['EmpDisclaimer'], "text"));

  mysql_select_db($database_nameprop, $nameprop);

  $Result1 = mysql_query($insertSQL, $nameprop) or die(mysql_error());

  header(sprintf("Location: %s", $insertGoTo));

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

  $insertSQL = sprintf("INSERT INTO name_landlord (name, `telephone number`, mobileNumber, email, address, dateday, datemonth, dateyear, terms) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",

                       GetSQLValueString($_POST['name'], "text"),

                       GetSQLValueString($_POST['telephone_number'], "text"),

                       GetSQLValueString($_POST['mobileNumber'], "text"),

                       GetSQLValueString($_POST['email'], "text"),

                       GetSQLValueString($_POST['address'], "text"),

                       GetSQLValueString($_POST['dateday'], "text"),

                       GetSQLValueString($_POST['datemonth'], "text"),

                       GetSQLValueString($_POST['dateyear'], "text"),

                       GetSQLValueString($_POST['terms'], "text"));

  mysql_select_db($database_nameprop, $nameprop);

  $Result1 = mysql_query($insertSQL, $nameprop) or die(mysql_error());

  $insertGoTo = "pay-online.php";

  if (isset($_SERVER['QUERY_STRING'])) {

    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";

    $insertGoTo .= $_SERVER['QUERY_STRING'];

  }

  header(sprintf("Location: %s", $insertGoTo));

}

mysql_select_db($database_nameprop, $nameprop);

$query_rsApplyNow = "SELECT * FROM name_editprop";

$rsApplyNow = mysql_query($query_rsApplyNow, $nameprop) or die(mysql_error());

$row_rsApplyNow = mysql_fetch_assoc($rsApplyNow);

$totalRows_rsApplyNow = mysql_num_rows($rsApplyNow);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<script type="text/javascript">

function loadFields(theValue) {

         var props = theValue.split("|");

          var prop_id = props[0];

          var propAdd = props[1] ;

          var propPrice = props[2];

                      var town = props[3]

                      var postcode = props[4]

          

          document.getElementById('prop_id').value=prop_id;

          document.getElementById('Add1').value=propAdd;

                      document.getElementById('town').value=town;

                      document.getElementById('postcode').value=postcode;

          document.getElementById('RentalPrice').value='£' + propPrice +'/ per month';

}

</script>

</head>

<body>

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">

  <input type="hidden" name="MM_insert" value="form1" />

<!-- Place the following code where you want to show the result of the property selection --><table width="100%" border="0" cellpadding="0">

  <tr>

    <td width="23%"><!-- the following code is just copied from your code -->

      <select name="Select Property" id="Select Property" onchange="loadFields(this.value)">

        <option value="select your property">select your property</option>

        <?php

do {

?>

        <option value="<?php echo $row_rsApplyNow['prop_id'] . '|' . $row_rsApplyNow['prop_add1'] . '|' . $row_rsApplyNow['rental_price'] . '|' . $row_rsApplyNow['town'] . '|' . $row_rsApplyNow['postcode'];?>"><?php echo $row_rsApplyNow['prop_id'] . " , " . $row_rsApplyNow['prop_add1']; ?></option>

        <?php

} while ($row_rsApplyNow = mysql_fetch_assoc($rsApplyNow));

  $rows = mysql_num_rows($rsApplyNow);

  if($rows > 0) {

      mysql_data_seek($rsApplyNow, 0);

            $row_rsApplyNow = mysql_fetch_assoc($rsApplyNow);

  }

?>

      </select></td>

    <td width="77%"> </td>

  </tr>

  <tr>

    <td>Property ID:</td>

    <td><input type="text" name="prop_id" id="prop_id" readonly="readonly" /></td>

  </tr>

  <tr>

    <td>Address</td>

    <td><input type="text" name="Add1" id="Add1" readonly="readonly" /></td>

  </tr>

  <tr>

    <td>Town</td>

    <td><input type="text" name="town" id="town" readonly="readonly" /></td>

  </tr>

  <tr>

    <td>Postcode</td>

    <td><label for="postcode"></label>

      <input type="text" name="postcode" id="postcode" readonly="readonly" /></td>

  </tr>

  <tr>

    <td>Rent</td>

    <td><input type="text" name="RentalPrice" id="RentalPrice" readonly="readonly" /></td>

  </tr>

  <tr>

    <td> </td>

    <td> </td>

  </tr>

  <tr>

    <td colspan="2"><table width="100%" border="0" cellpadding="0">

      <tr>

        <td>tenant</td>

        <td>gaurantor</td>

        <td>landlord</td>

      </tr>

      <tr>

        <td><table align="center">

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Title:</td>

            <td><input type="text" name="Title" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">First Names:</td>

            <td><input type="text" name="First_Names" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Surname:</td>

            <td><input type="text" name="Surname" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DOB:</td>

            <td><input type="text" name="DOB" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DOBMonth:</td>

            <td><input type="text" name="DOBMonth" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DOBYear:</td>

            <td><input type="text" name="DOBYear" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Nationality:</td>

            <td><input type="text" name="Nationality" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Marital_Status:</td>

            <td><input type="text" name="Marital_Status" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DayNumber:</td>

            <td><input type="text" name="DayNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EvenNumber:</td>

            <td><input type="text" name="EvenNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">MobNumber:</td>

            <td><input type="text" name="MobNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Smoker:</td>

            <td><input type="text" name="Smoker" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">CurrentAdd:</td>

            <td><input type="text" name="CurrentAdd" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Status:</td>

            <td><input type="text" name="Status" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">PreviousAdd:</td>

            <td><input type="text" name="PreviousAdd" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Student:</td>

            <td><input type="text" name="Student" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">FinancialCCj:</td>

            <td><input type="text" name="FinancialCCj" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">FinancialArrears:</td>

            <td><input type="text" name="FinancialArrears" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">FinancialBankR:</td>

            <td><input type="text" name="FinancialBankR" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">FinancialNone:</td>

            <td><input type="text" name="FinancialNone" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">BankName:</td>

            <td><input type="text" name="BankName" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">AccountNum:</td>

            <td><input type="text" name="AccountNum" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">SortCode:</td>

            <td><input type="text" name="SortCode" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">BankDuration:</td>

            <td><input type="text" name="BankDuration" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DebitCCCard:</td>

            <td><input type="text" name="DebitCCCard" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Electoral:</td>

            <td><input type="text" name="Electoral" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Next of kin:</td>

            <td><input type="text" name="next_of_kin" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right"> </td>

            <td> </td>

          </tr>

        </table></td>

        <td><table align="center">

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">FullName:</td>

            <td><input type="text" name="FullName" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Title:</td>

            <td><input type="text" name="Title2" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DOBday:</td>

            <td><input type="text" name="DOBday" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DOBMonth:</td>

            <td><input type="text" name="DOBMonth2" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DOBYear:</td>

            <td><input type="text" name="DOBYear2" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Sex:</td>

            <td><input type="text" name="Sex" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">MaritalStatus:</td>

            <td><input type="text" name="MaritalStatus" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">DaytimeNumber:</td>

            <td><input type="text" name="DaytimeNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EveningNumber:</td>

            <td><input type="text" name="EveningNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">MobileNumber:</td>

            <td><input type="text" name="MobileNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Email:</td>

            <td><input type="text" name="Email" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">CurrentAddress:</td>

            <td><input type="text" name="CurrentAddress" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">PreviousAddress:</td>

            <td><input type="text" name="PreviousAddress" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">BankName:</td>

            <td><input type="text" name="BankName2" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">AccountNum:</td>

            <td><input type="text" name="AccountNum2" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">SortCode:</td>

            <td><input type="text" name="SortCode2" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">BankDuration:</td>

            <td><input type="text" name="BankDuration2" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">CCDebitCard:</td>

            <td><input type="text" name="CCDebitCard" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">ElectoralRoll:</td>

            <td><input type="text" name="ElectoralRoll" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Profession:</td>

            <td><input type="text" name="Profession" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">AnnualWages:</td>

            <td><input type="text" name="AnnualWages" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">PayrollNum:</td>

            <td><input type="text" name="PayrollNum" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpName:</td>

            <td><input type="text" name="EmpName" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpAddress:</td>

            <td><input type="text" name="EmpAddress" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpContName:</td>

            <td><input type="text" name="EmpContName" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpContNumber:</td>

            <td><input type="text" name="EmpContNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpEmail:</td>

            <td><input type="text" name="EmpEmail" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpFinaHist:</td>

            <td><input type="text" name="EmpFinaHist" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpDate:</td>

            <td><input type="text" name="EmpDate" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">EmpDisclaimer:</td>

            <td><input type="text" name="EmpDisclaimer" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right"> </td>

            <td> </td>

          </tr>

        </table></td>

        <td><table align="center">

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Name:</td>

            <td><input type="text" name="name" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Telephone number:</td>

            <td><input type="text" name="telephone_number" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">MobileNumber:</td>

            <td><input type="text" name="mobileNumber" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Email:</td>

            <td><input type="text" name="email" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Address:</td>

            <td><input type="text" name="address" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Dateday:</td>

            <td><input type="text" name="dateday" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Datemonth:</td>

            <td><input type="text" name="datemonth" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Dateyear:</td>

            <td><input type="text" name="dateyear" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right">Terms:</td>

            <td><input type="text" name="terms" value="" size="32" /></td>

          </tr>

          <tr valign="baseline">

            <td nowrap="nowrap" align="right"> </td>

            <td><input type="submit" value="Insert record" /></td>

          </tr>

        </table></td>

      </tr>

    </table></td>

    </tr>

</table>

</form>

<p> </p>

<p> </p>

</form>

<p> </p>

</body>

</html>

<?php

mysql_free_result($rsApplyNow);

?>

This topic has been closed for replies.

1 reply

Participating Frequently
November 15, 2011

Jon, I also just replied to your other thread.

>i have the understanding that because the guarantorID, landlordID and propertyID

>are all inputting new data these will be input commands, however the property is

 

As I asked in the other thread, do you really want to input landlord and guarantor data everytime you input a tenant? Don't you want to be able to reuse any of this data? Or would you NEVER deal with a given landlord more than once?

The purpose of splitting data into multiple tables is to eliminate redundant data. For example, if one landlord is related to 10 tenants, you wouldn't want to enter all of the same landlord data 10 times, right? But that's what you are doing in your current code.

If for some reason you really do need to enter all of that data each time, then just put it all in one table.

>however the property is already in the table so this will be an update command?

Why do you need to update the property? You would update the property only when an attribute of the property has changed. Same goes for the other tables. You update them when something has changed.

>what i need to do is when the form is submitted the guarantorID, landlordID

>and propertyID  all are sent to columns in the tenant table.

Again, you need to first generate the unique id's for guarantor and landord before you can insert them into the tenant table.

>this is called join i believe?

No, this is not a JOIN. This is just a logical relation.

It would be really helpful to understand what type of application you are building. What is the purpose, and who is entering the various data? Without knowing that, I'm just guessing but I would not build the app this way. I would create a separate maintenance page for each entity - tenant, landlord, guarantor and property. On each page you can INSERT or UPDATE data. The tenant page would consists of 3 dropdown's as well as the other tenant text fields. You would select the guarantor, property and landlord from the dropdowns and these would populate the data for the tenant.

Inspiring
November 15, 2011

ok, let me try and explain the form that i am building. I have a page that i insert the properties on. this then goes into the database. the property table has information like, property id, address, postcode and a few others.

the the tenant who wants to have / stay in one of these properties applies to stay in one. they goes to an application form where they first select the property they want to stay in (this is the drop down menu) they then fill out the tenant part of the form / the guarantor part of the form and the landlord part of the form. So the tenant fill all them parts out.

Once the form has been filled out this needs to be emailed to me. this also needs to be sent to the database. I then review the information and as soon as i agree the information on the  form i go to an application page ( this consists of all the data the tenant submitted by email and to the database. I then click a box, the activates the yes/no on the tenant page then they are allowed to access their own unique page. I have done this part of it.

so each part of data, the tenant, landlord (these are old landlords of the tenant) and guarantor are unque to the tenant so do need to be entered everytime

Participating Frequently
November 15, 2011

>so each part of data, the tenant, landlord (these are old landlords of the tenant)

>and guarantor are unque to the tenant so do need to be entered everytime

OK, this is very helpful. As mentioned in another post, separating the data into multiple tables is used to eliminate redundant data and resolve other data normalization issues. But in this case, there is no point and only complicates things for you as all of the data has a 1 to 1 relationship. So what I would suggest is to combine all of the fields from tenant, landlord and guarantor into a single table. To that table also add a column for propertyID. Now, in the form that the user fills out, you would include all of these fill-in fields and also include the dropdown where they select the property.  When the form is submitted, all of the data they've filled in, plus the propertyID will get passed to the INSERT statement.  Now I know you also want to display the property details when they select the property.  You can still do that the way you were doing before using JavaScript - just don't insert this additional data into the table.

If for some reason you really want to split the data into multiple tables, then it will be more complicated. You would need to first insert the data into the tenant table, retrieve the unique key value, and then pass that value to the other INSERT statements for landlord and guarantor.

Hope this helps.