PDA

View Full Version : Update Form Not Working


toad78
03-06-2009, 01:09 AM
I have an update form that I seem be having trouble updating a record.

I have two tables: #1 employee
empl_id
staff_id
empl_month

#2 staff
staff_id
staff_name
staff_photo

The 'staff' table stores the information regarding a staff member (name, image filename, and other such information). The 'employee' table stores the 'staff_id' from 'staff'. The 'employee' table is being drawn from another web page which posts the Employee of the Month. Confused so far?

What I want to happen is for the admin to be able to update that record by selecting a different employee name and a different month. I have no trouble getting the month to update, but it's the 'staff_id' I can't get to change.

Can someone tell me where I'm going wrong?

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
$updateSQL = sprintf("UPDATE employee SET staff_id=%s, empl_month=%s WHERE empl_id=%s",
GetSQLValueString($_POST['staff_id'], "int"),
GetSQLValueString($_POST['empl_month'], "text"),
GetSQLValueString($_POST['staff_id'], "int"));

mysql_select_db($database_wvgsadmin, $wvgsadmin);
$Result1 = mysql_query($updateSQL, $wvgsadmin) or die(mysql_error());

$updateGoTo = "eotm_list.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_getEotm = "-1";
if (isset($_GET['empl_id'])) {
$colname_getEotm = $_GET['empl_id'];
}
mysql_select_db($database_wvgsadmin, $wvgsadmin);
$query_getEotm = sprintf("SELECT * FROM employee WHERE empl_id = %s", GetSQLValueString($colname_getEotm, "int"));
$getEotm = mysql_query($query_getEotm, $wvgsadmin) or die(mysql_error());
$row_getEotm = mysql_fetch_assoc($getEotm);
$totalRows_getEotm = mysql_num_rows($getEotm);

mysql_select_db($database_wvgsadmin, $wvgsadmin);
$query_getStaff = "SELECT staff_name, staff_photo FROM staff";
$getStaff = mysql_query($query_getStaff, $wvgsadmin) or die(mysql_error());
$row_getStaff = mysql_fetch_assoc($getStaff);
$totalRows_getStaff = mysql_num_rows($getStaff);
?>Here's my form:
<form method="post" name="form2" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Employee Name:</td>
<td><select name="staff_id" id="staff_id">
<option></option>
</select>
</td>
<tr>
<tr valign="baseline">
<td nowrap align="right">Date:</td>
<td><select name="empl_month" value="<?php echo $row_getEotm['empl_month']; ?>">
<option value="January" <?php if (!(strcmp("January", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>January</option>
<option value="February" <?php if (!(strcmp("February", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>February</option>
<option value="March" <?php if (!(strcmp("March", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>March</option>
<option value="April" <?php if (!(strcmp("April", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>April</option>
<option value="May" <?php if (!(strcmp("May", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>May</option>
<option value="June" <?php if (!(strcmp("June", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>June</option>
<option value="July" <?php if (!(strcmp("July", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>July</option>
<option value="August" <?php if (!(strcmp("August", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>August</option>
<option value="September" <?php if (!(strcmp("September", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>September</option>
<option value="October" <?php if (!(strcmp("October", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>October</option>
<option value="November" <?php if (!(strcmp("November", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>November</option>
<option value="December" <?php if (!(strcmp("December", $row_getEotm['empl_month']))) {echo "SELECTED";} ?>>December</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Update record"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="empl_id" value="<?php echo $row_getEotm['empl_id']; ?>">
</form>

I would appreciate anyone help this rookie pull through this.

Thank you!
toad78

edbr
03-06-2009, 02:05 AM
check
<?php echo $row_getEotm['empl_id']; ?> is returning a value

toad78
03-06-2009, 06:22 AM
Thank you. It worked out well!