...

View Full Version : populating textboxes from mysql



warzo69
10-05-2008, 02:57 AM
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,


<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>

shyam
10-05-2008, 09:12 AM
...
<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 :eek: no mixing of server-side/client-side code...


$result = mysql_query("select ssn from employee where fullname='" . $_POST['txtfullname'] . "'");

warzo69
10-05-2008, 09:34 AM
is there another way to do this client side? i havent been able to get this to work. I have tried


$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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum