Forums

PHP

This topic is locked

Form Question

Posted 19 Apr 2007 18:01:14
1
has voted
19 Apr 2007 18:01:14 Christie Applegate posted:
I am trying to create a form to update records in the database. It works if you type in the name but I want to populate the information in the form from what is in the database using a dropdown for the person's name. I have the box pulling the names but don't know how to have the form change the information based on the data chosen. I know it is just a simple step but I haven't done it before and can't seem to find the right question to ask to get the answer I need. Please help!
Christie

Replies

Replied 19 Apr 2007 18:11:07
19 Apr 2007 18:11:07 Javier Castro replied:
what do you have so far. Can you psot the code?
Replied 19 Apr 2007 18:20:24
19 Apr 2007 18:20:24 Christie Applegate replied:
Here is part of the table coding and sql statements
<?php
mysql_select_db($database_EMCOffice, $EMCOffice);
$query_Users = "SELECT users.UserID, users.UserAccess, users.UserFirstName, users.UserLastName, users.UserName, users.UserPassword, users.UserEmail, employees.EmployeeFirst, employees.EmployeeLast, employees.EmployeePhone, employees.EmployeeMobil, employees.EmployeeExt, employees.EMPSpouse, employees.EMPAdd, employees.EMPCity, employees.EMPState, employees.EMPZip, employees.DOB, employees.EmployeeJob FROM users, employees WHERE employees.EmployeeFirst = users.UserFirstName AND employees.EmployeeLast = users.UserLastName ORDER BY users.UserFirstName ASC";
$Users = mysql_query($query_Users, $EMCOffice) or die(mysql_error());
$row_Users = mysql_fetch_assoc($Users);
$totalRows_Users = mysql_num_rows($Users);

mysql_select_db($database_EMCOffice, $EMCOffice);
$query_AccessGroups = "SELECT * FROM accessgroups";
$AccessGroups = mysql_query($query_AccessGroups, $EMCOffice) or die(mysql_error());
$row_AccessGroups = mysql_fetch_assoc($AccessGroups);
$totalRows_AccessGroups = mysql_num_rows($AccessGroups);

mysql_select_db($database_EMCOffice, $EMCOffice);
$query_FirstName = "SELECT employees.EmployeeFirst, users.UserFirstName, users.UserID FROM employees, users WHERE users.UserFirstName = employees.EmployeeFirst ORDER BY users.UserFirstName ASC";
$FirstName = mysql_query($query_FirstName, $EMCOffice) or die(mysql_error());
$row_FirstName = mysql_fetch_assoc($FirstName);
$totalRows_FirstName = mysql_num_rows($FirstName);

mysql_select_db($database_EMCOffice, $EMCOffice);
$query_LastName = "SELECT employees.EmployeeLast, users.UserLastName FROM employees, users WHERE users.UserLastName = employees.EmployeeLast ORDER BY users.UserLastName ASC";
$LastName = mysql_query($query_LastName, $EMCOffice) or die(mysql_error());
$row_LastName = mysql_fetch_assoc($LastName);
$totalRows_LastName = mysql_num_rows($LastName);
?>

<table width="100%" border="0" cellspacing="0" cellpadding="0">

<tr>
<td height="40"><table width="100%" class="layoutTable" border="0" cellpadding="6" cellspacing="0">
<tr>
<td width="175" align="center" valign="bottom" bgcolor="#6699CC" class="pageHeader">EDIT
USER</td>
<td bgcolor="#336699"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><form action="" name="EditUser" method="POST">
<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="25"> </td>
<td colspan="2" class="smallText"> </td>
</tr>
<tr>
<td width="25"> </td>
<td colspan="2" class="emc"><h3 align="left">User Profile</h3></td>
</tr>
<tr>
<td width="25"> </td>
<td class="emc"><div align="right">First Name</div></td>
<td class="formField"><select name="FirstName" id="FirstName">
<option value="%"></option>
<?php
do {
?>
<option value="<?php echo $row_FirstName['EmployeeFirst']?>"><?php echo $row_FirstName['EmployeeFirst']?></option>
<?php
} while ($row_FirstName = mysql_fetch_assoc($FirstName));
$rows = mysql_num_rows($FirstName);
if($rows > 0) {
mysql_data_seek($FirstName, 0);
$row_FirstName = mysql_fetch_assoc($FirstName);
}
?>
</select></td>
</tr>

<tr>
<td width="25"> </td>
<td class="emc"><div align="right">User Name</div></td>
<td class="formField"><input name="UserName" type="text" id="UserName" value="<?php echo $row_Users['UserName']; ?>" size="30"></td>
</tr>
<tr>
Replied 19 Apr 2007 22:54:13
19 Apr 2007 22:54:13 Javier Castro replied:
basically, your sql should have something like this:

A form with your drop down menu. Let's call your menu: search (or wahtever you choose)

This: recordset to populate your Menu

SELECT *
FROM tblUsers
ORDER by lastname ASC

Next page the detail page will have a recordset that is similar to the one above but it should have in your SQL

SELECT *
FROM tblUsers
WHERE LastName = Param (or) LastName LIKE Param
ORDER by lastname ASC

And

or your parameters you create a new one called:

name: param
Type: text or numeric depending (try numeric first)
value: Request.QueryString("search" the same as the name of your prodown menu
Default value: 0 if you are using LIKE on your SQL instead of = Then you should try % (depending what is the wild card in MySQL)

Once you have that.
Try that. Good luck
Replied 20 Apr 2007 22:15:23
20 Apr 2007 22:15:23 Christie Applegate replied:
That would work if I were going to a different page but I want the form to fill in with data from the name selected on the same page in the same form. I have found some JavaScript which would work but don't know exactly how to integrate it into the php page.

Reply to this topic