Page 2 of 2

Re: text area loading from mysql database

Posted: Fri Oct 10, 2008 2:57 am
by warzo69
I have tried a few more things, here is what the code looks like now:

Code: Select all

 <head>
 
<script src="empedit.js" type="text/javascript" language="javascript"></script>
 
  </head>
 
        <form name="form1">
 
<div align="left">
  <table width="825" border="0" bgcolor="#FAFAFA">
    <tr>
      <td width="155" rowspan="6" valign="top">
        <div align="center">
            <select name="select1" id="select1" onChange='empsel()'/> 
  <?php
  $result = mysql_query("SELECT fullname FROM employee");
  while ($row = mysql_fetch_array($result)) {
      echo "<option>".$row['fullname']."</option><br>";
  };
  ?>
              <option>New Employee</option>
            </select>
            <br/>
            <br/>
            <br/>
            <br/>
   
           <textarea name="txtempinfo" rows="5" cols="15" id="txtempinfo" onChange='empsel1()'/>
<?php  
$select = mysql_real_escape_string($_POST["select1"]);
  $result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '$select' ") or die(mysql_error());
  while ($row = mysql_fetch_array($result)) {
      echo "".$row['ssn']."|"."".$row['dob']."|"."".$row['add1']."|"."".$row['add2']."|".
           "".$row['phone']."|"."".$row['empid']."|"."".$row['position']."|"."".$row['hiredate']."|".
           "".$row['termdate']."|"."".$row['status']."|"."".$row['salary']."|"."".$row['driverslicense']."";
  };
   
?>  
            </textarea>
 
 
      </td>
    <td width="299" height="10">Full Name or DBA
      </td>         
    <td width="151" height="10">SSN / Tax ID
      </td>         
    <td width="151" height="10">Position
      </td>
    </tr>
    <tr>
      <td width="299" height="10">
        <div align="left">
          <input type="text" name="txtfullname" id='txtfullname' value="Full Name or DBA"/>
        </div>
      </td>
      <td width="151" height="10">
        <div align="center">
          <input type="text" name="txtssn" id='txtssn'/>
        </div>
      </td>
      <td width="151" height="10">
        <div align="center">
          <input type="text" name="txtposition" id="txtposition"/>
        </div>
      </td>
    </tr>
    <tr>
      <td width="299" height="10">Address
      </td>         
    <td width="151" height="10">Drivers License #
      </td>         
    <td width="151" height="10">Start Date
      </td>
    </tr>
    <tr>
      <td width="299" height="10"> 
        <div align="center">
          <input name="txtadd1" id="txtadd1" type="text" value="Street Address"/>
          <input name="txtadd2" id="txtadd2" type="text" value="City State Zip"/>
        </div>
      </td>
      <td height="10">      
        <div align="center">
          <input type="text" name="txtdriverslicense" id="txtdriverslicense"/>
        </div>
      </td>
      <td height="10">
        <div align="center">
          <input type="text" name="txthiredate" id="txthiredate"/>
        </div>
      </td>
    </tr>
    <tr>
      <td width="299" height="10">Phone Number
      </td>         
    <td width="151" height="10">Employee ID Number
      </td>         
    <td width="151" height="10">Term Date
      </td>
    </tr>
    <tr height="20">
      <td width="299" height="10"> 
        <div align="left">
          <input name="txtphone" id="txtphone" type="text" value="XXX-XXX-XXXX"/>
        </div>
      </td>
      <td height="10">   
        <div align="center">
          <input type="text" name="txtempid" id="txtempid"/>
        </div>
      </td>
      <td height="10">
        <div align="center">
          <input type="text" name="txttermdate" id="txttermdate"/>
        </div>
      </td>
    </tr>
    <tr>
      <td height="20" rowspan="2">
        <div align="center">
          
        </div>
      </td>
      <td width="299" height="10">Date Of Birth
      </td>         
    <td width="151" height="10">Status 
      </td>         
    <td width="151" height="10">Salary 
      </td>
    </tr>
      <td width="299" height="10">
        <div align="left">
          <input type="text" name="txtdob" id="txtdob"/>
        </div>
      </td>
      <td height="10">
        <div align="left">
          <select name="txtstatus" id="txtstatus"/>
            <option>Active</option>
            <option>Inactive</option>
          </select>
        </div>
      </td>
      <td height="10">
        <div align="center">
          <input type="text" name="txtsalary" id="txtsalary"/>
        </div>
      </td>
    </tr>
  </table>
        </form>  
  </div>
 
 

Code: Select all

function empsel() {
document.getElementById('txtfullname').value = document.getElementById('select1').value;
}
function empsel1() {
var empinfo = document.getElementById('txtempinfo').value;
var emparry = new Array();
emparry = empinfo.split('|');
 
document.getElementById('txtssn').value = emparry[0]; 
document.getElementById('txtdob').value = emparry[1]; 
document.getElementById('txtadd1').value = emparry[2]; 
document.getElementById('txtadd2').value = emparry[3]; 
document.getElementById('txtphone').value = emparry[4]; 
document.getElementById('txtempid').value = emparry[5];
document.getElementById('txtposition').value = emparry[6]; 
document.getElementById('txthiredate').value = emparry[7]; 
document.getElementById('txttermdate').value = emparry[8]; 
document.getElementById('txtstatus').value = emparry[9]; 
document.getElementById('txtsalary').value = emparry[10]; 
document.getElementById('txtdriverslicense').value = emparry[11];  
}
 

Re: text area loading from mysql database

Posted: Fri Oct 10, 2008 5:10 am
by papa
You don't have a value="" in your dropdown menu (select). Might be worth checking out.

Code: Select all

<?php
$result = mysql_query("SELECT fullname FROM employee");
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"".$row['fullname']."\">".$row['fullname']."</option><br>";
};
?>

Re: text area loading from mysql database

Posted: Fri Oct 10, 2008 7:01 am
by warzo69
same result. Empty textarea.

Re: text area loading from mysql database

Posted: Fri Oct 10, 2008 7:13 am
by aceconcepts
Can you show the code you currently have?

Re: text area loading from mysql database

Posted: Fri Oct 10, 2008 7:56 am
by papa

Code: Select all

 
        <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
.....
 
<?php  
$select = mysql_real_escape_string($_POST["select1"]);
$result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = '".$_POST['select1']."'") or die(mysql_error());