Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    2
    Thanked 4 Times in 4 Posts

    populating textboxes from mysql

    Im building a payroll website and have a snag that I can figureout with mysql_query("SELECT. I have a form that has a select box with employee names. the select box is generated from a mysql database. when the name is changed "a new name is selected" I need the rest of their information to be generated into textboxes the same way. all the employee information is stored in a mysql database. does anyone know how to make this work? the part of the code that is not working is noted in the code. If there is another way to store the data securely so that I dont have to use php to connect to it let me know.

    Thanks,

    Code:
      <head>
    
    <script language="javascript">
    
    function empsel() {
    document.getElementById('txtfullname').value = document.getElementById('select1').value;
    }
    
    </script>
    
      </head>
    
            <form name="form1">
    <?php
    	# this is processed when the form is submitted
    	# back on to this page (POST METHOD)
    
    if ($_POST["select1"]=="New Employee") {
    
    	# setup SQL statement
    	$SQL = " INSERT INTO employee ";
    	$SQL = $SQL . " (fullname, ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense) VALUES ";
    	$SQL = $SQL . " ('$txtfullname', '$txtssn', '$txtdob', '$txtadd1', '$txtadd2', '$txtphone', '$txtempid', '$txtposition', '$txthiredate', '$txttermdate', '$txtstatus', '$txtsalary' '$txtdriverslicense') ";
    
    	$result = mysql_db_query($database,"$SQL",$dataconn);
    
    	if (!$result) { echo("ERROR: " . mysql_error() . "$SQL");	}
    } 
    		
    
    ?>
    <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>
              <select name="select2" id="select2"/>
    <?php
    //this is where the error is
    //
    //
    $result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname = 'document.getElementById('txtfullname')'"); 
    while ($row = mysql_fetch_array($result)) {
        echo "<option>".$row['ssn']."</option><br>";
    };
    
    ?>
              </select>
          </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"/>
            </div>
          </td>
          <td width="151" height="10">
            <div align="center">
              <input type="text" name="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" type="text" value="Street Address"/>
              <input name="txtadd2" type="text" value="City State Zip"/>
            </div>
          </td>
          <td height="10">      
            <div align="center">
              <input type="text" name="txtdriverslicense"/>
            </div>
          </td>
          <td height="10">
            <div align="center">
              <input type="text" name="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" type="text" value="XXX-XXX-XXXX"/>
            </div>
          </td>
          <td height="10">   
            <div align="center">
              <input type="text" name="txtempid"/>
            </div>
          </td>
          <td height="10">
            <div align="center">
              <input type="text" name="txttermdate"/>
            </div>
          </td>
        </tr>
        <tr>
          <td height="20" rowspan="2">
            <div align="center">
              <input type="submit" value="Save">
            </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"/>
            </div>
          </td>
          <td height="10">
            <div align="left">
              <select name="txtstatus"/>
                <option>Active</option>
                <option>Inactive</option>
              </select>
            </div>
          </td>
          <td height="10">
            <div align="center">
              <input type="text" name="txtsalary"/>
            </div>
          </td>
        </tr>
      </table>
            </form>  
      </div>

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by warzo69 View Post
    Code:
     ...
              <select name="select2" id="select2"/>
    <?php
    //this is where the error is
    //
    //
    $result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense ".
        "FROM employee WHERE fullname = 'document.getElementById('txtfullname')'"); 
    while ($row = mysql_fetch_array($result)) {
        echo "<option>".$row['ssn']."</option><br>";
    };
    
    ?>
              </select>
    ...
    well, the problem is actually staring at you right in the face no mixing of server-side/client-side code...

    PHP Code:
    $result mysql_query("select ssn from employee where fullname='" $_POST['txtfullname'] . "'"); 
    Last edited by shyam; 10-05-2008 at 09:14 AM. Reason: fixed alignment
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    32
    Thanks
    2
    Thanked 4 Times in 4 Posts
    is there another way to do this client side? i havent been able to get this to work. I have tried

    Code:
    $result = mysql_query("SELECT ssn, dob, add1, add2, phone, empid, position, hiredate, termdate, status, salary, driverslicense FROM employee WHERE fullname='$_POST["select2"]'",);
    with many diffrent variations. I have been trying to get this 1 line of code to work for 3 weeks. none of the php guys have any idea how to fix this and I will be bald if I cant figure this out soon. is there any way to handle this using ajax?
    Last edited by warzo69; 10-05-2008 at 01:58 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •