Hi!
So, I have one page where I select a record which I want to edit... the records are in a drop down menu which are sorted by name. When I select a record on the list to edit and click Submit, I wanted it to go to the next page and display the record I selected.. But with my code, it always displays the first record, and I am not sure why. Does anyone spot what I've done wrong?
Here is the code for where I select the record:
$query = "SELECT * FROM acctmgr";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo '<form action="edit_acctmgr.php?acctmgr_name='.$row['acctmgr_name'].'" method="post">
<table align=left border="0" width="80%" cellpadding="0" cellspacing="0" summary="MAIN TABLE">
<TR>
<td ROWSPAN=88888 bgcolor="#ccccff" valign="top" height="80" width="100"><CENTER><img alt="logo_sm (1K)" src="logo_sm.gif" height="80" width="67"><BR><font face="Tahoma" size=2 color="black"><B>I-DEP DIW Management Tool<BR>-----<BR><a href=damndiw1.php>Create new DIW</A><BR>-----<BR><a href=damndiw3.php>View DIW List</A><BR>-----<BR><a href=damndiw6.php>Calendar</A><BR>-----<BR><a href=diw_admin.html>DIW Admin</A></B></FONT></CENTER></TD>
<TD valign="top">
<TABLE>
<tr>
<td width=600 colspan=2 bgcolor="#000080"><font face="Tahoma" size="5" color="white"> I-DEP - DIW Admin </font></td>
</tr>
<TR>
<td colspan=2 bgcolor="#ccccff" width=600><font face="Tahoma" size=2 color="black"><b>Select Account Manager </b></font></td>
</TR>
<TR>
<td width="20%"><b><font face="Tahoma" size=2>Account Manager</font></b></small></td>
<td><select name="dropdownacctmgr" tabindex="4"><option value="notset">- Edit Account Manager -</option>';
//--- CREATE Account Manager SELECT ---
$sql = "SELECT DISTINCT acctmgr_name FROM acctmgr ORDER BY acctmgr_name";
$acctmgr_name = mysql_query($sql) or die($sql . '<br />' . mysql_error());
while ($row = mysql_fetch_array($acctmgr_name)) {
echo '<option value="' . $row['acctmgr_name'] . '">' . $row['acctmgr_name'] . '</option>';
}
And here is the code where I try to display the data for editing:
if(!empty($_REQUEST['action']) && $_REQUEST['action'] == 'update')
{
$acctmgr_name = $_REQUEST['acctmgr_name'];
$_GET['acctmgr_name'] = $acctmgr_name;
$query = "UPDATE `acctmgr` SET acctmgr_name = '".$_REQUEST['newacctmgr_name']."',acctmgr_phone = '".$_REQUEST['newacctmgr_phone']."',acctmgr_cellphone = '".$_REQUEST['newacctmgr_cellphone']."',acctmgr_email = '".$_REQUEST['newacctmgr_email']."' WHERE id='$id'";
$result = mysql_query($query) or die("<b>mySQL Error:</b>".mysql_errono()."<br>".mysql_error());
if(!$result)
{
echo 'Error processing request.';
}
else
{
echo 'Request processed successfully.';
}
}
$acctmgr_name = $_GET['acctmgr_name'];
// The ID is passed through the URL to specify the row,
// Or it is set in the previous script.
$query = "SELECT * FROM acctmgr WHERE acctmgr_name = '$acctmgr_name'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo '<form name="update" method="post">
<input type="hidden" value="update" name="action">
<input type="hidden" name="id" value="'.$id.'">
<table align=left border="0" width="80%" cellpadding="0" cellspacing="0" summary="MAIN TABLE">
<TR>
<td ROWSPAN=88888 bgcolor="#ccccff" valign="top" height="80" width="100"><CENTER><img alt="logo_sm (1K)" src="logo_sm.gif" height="80" width="67"><BR><font face="Tahoma" size=2 color="black"><B>I-DEP DIW Management Tool<BR>-----<BR><a href=damndiw1.php>Create new DIW</A><BR>-----<BR><a href=damndiw3.php>View DIW List</A><BR>-----<BR><a href=damndiw6.php>Calendar</A><BR>-----<BR><a href=diw_admin.html>DIW Admin</A></B></FONT></CENTER></TD>
<TD valign="top">
<TABLE>
<tr>
<td width=600 colspan=2 bgcolor="#000080"><font face="Tahoma" size="5" color="white"> I-DEP - DIW Admin </font></td>
</tr>
<TR>
<td colspan=2 bgcolor="#ccccff" width=600><font face="Tahoma" size=2 color="black"><b>Edit Account Manager </b></font></td>
</TR>
<TR>
<TD><B>Account Manager Name</B></TD>
<TD><input type="text" name="newacctmgr_name" size="40" value="'.$row['acctmgr_name'].$resstring .'"></TD>
</TR>
<TR>
<TD><B>Phone Number</B></TD>
<TD><input type="text" name="newacctmgr_phone" size="12" value="'.$row['acctmgr_phone'].'"></TD>
</TR>
<TR>
<TD><B>Cell</B></TD>
<TD><input type="text" name="newacctmgr_cellphone" size="12" value="'.$row['acctmgr_cellphone'].'"></TD>
</TR>
<TR>
<TD><B>Email Address</B></TD>
<TD><input type="text" name="newacctmgr_email" size="32" value="'.$row['acctmgr_email'].'"></TD>
</TR>
<TR>
<TD COLSPAN=4><input type="submit" value="Update"> </form></TD>
</TR>
</TABLE>';
?>
Help!