SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    822
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question Update Record Form Not Showing Correct Record to Update

    I have a record update form that is not displaying the correct employee that is selected from a different web page.

    It will display the correct month, but not the correct employee name.

    Can someone show me where I'm going wrong?

    PHP Code:
    $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);
    ?> 
    HTML Code:
    <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">
    <?php
    do {  
    ?>
    <option value="<?php echo $row_getStaff['staff_name']?>"<?php if (!(strcmp($row_getStaff['staff_name'], $row_getEotm['staff_id']))) {echo "selected=\"selected\"";} ?>><?php echo $row_getStaff['staff_name']?></option>
    <?php
    } while ($row_getStaff = mysql_fetch_assoc($getStaff));
      $rows = mysql_num_rows($getStaff);
      if($rows > 0) {
          mysql_data_seek($getStaff, 0);
    	  $row_getStaff = mysql_fetch_assoc($getStaff);
      }
    ?>
    </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>
    Thank you for looking at this for me!
    toad78

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Are you certain about this:
    PHP Code:
    if (!(strcmp($row_getStaff['staff_name'], $row_getEotm['staff_id']))) 
    First of all I find it strange that columns named like that would mean the same data, but who knows (just thinking that I wouldn't expect a field labeled Emplyee Name to be an int data type). But then, if they are not equal you want that option selected? Somehow I think that should result in all (or all but one) options selected in the source of html output.

  3. #3
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    822
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Red face

    No...I'm not certain. I think that's where I'm getting confused. I want the value that is selected from a web page (the client clicks EDIT on the selected employee) to appear in this area. Then to populate the menu with other employee names that are coming from 'staff'. After the name is selected, to change the record information within 'employee'.

    Like I said, I think that is where I'm getting confused and need help rethink my logic here when creating this.

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try to change that 'if' to:
    PHP Code:
    if($colname_getEotm == $row_getStaff['staff_id']) 
    And for that to work you need to select staff_id (or whatever the appropriate column is called) from the staff table as well. In this query:
    Code:
    SELECT staff_name, staff_photo, staff_id FROM staff

  5. #5
    SitePoint Guru
    Join Date
    Jul 2003
    Location
    england
    Posts
    822
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thank you. After struggling with it for a couple more hours, I finally found that to be the issue.

    I guess it pays to sweat it out for awhile.

    Thank you again!


Bookmarks

Posting Permissions

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