Jump to content

Update recordset from dropdown values?


A JM

Recommended Posts

I'm trying to update records in my DB from a form that uses a dropdown for allowing web users to assign/select users to particular records in my DB (see image).

 

I've attached what I think is a start of the working code for this process but after I tested, it doesn't do what I anticipated - so I need some help solving this.

 

The DB or recordset for the form comes from the table "claimcue" which contains ID, repair, descr, adj_id, etc. The records for the user dropdown come out of the table "users" which contains ID, username, contact fields.

 

So, from the image you can see that I have a dropdown that is populated with the "username" in the "users" table . I want to update my "claimcue" table on "SUBMIT / POST" withthe ID of the user from the "Users" table.

 

$theusers = '';
$theusers .= '<select name=\"adj[]\"><option value="">Please Select</option>';
while ($row = mysql_fetch_assoc($rst_adjusters)) {
$theusers .= '<option value="' . $row['ID'] . '">' . $row['firstname'] . ' ' . $row['lastname'] . '</option>';
}
$theusers .= '</select>';

 

and this if from the form so you can see its populating correctly:

 

<select name=\"adj[]\"><option value="">Please Select</option><option value="29">Steve Jobs</option><option value="34">Bill Gates<...

 

 

The code below is my attempt at looping through the "claimcue" recordset which is limited to 10 items per page and updating the field "adj_id" with the ID of the item selected from the dropdown using the field "ID" from the "users" table.

 

<?php
//Edit Claim records with adjuster who is to handle the claim
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
        $i = 0;
        while ($row = mysql_fetch_assoc($rstassign))
        {
          $adjID = $_POST['adj'][$i];
//echo "<script>alert('" . $adjID . "')</script>";
                if($adjID<>'Please Select')
                {
                  $updateSQL = sprintf("UPDATE claimcue SET adj_id=555");
                  mysql_select_db($database_maxdbconn, $maxdbconn);
                  $Result1 = mysql_query($updateSQL, $maxdbconn) or die(mysql_error());
                }
        $i++;
        //echo "<script>alert('" . $i ."')</script>";
        }
}
?>

 

 

My problem is that $adjID = $_POST['adj'][$i]; doesn't contain any of the dropdown ID's and the DB isn't being updated..

 

Let me know if this doesn't make sense or if I wasn't clear enough - any help would be appreciated.

 

Thanks,

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/161723-update-recordset-from-dropdown-values/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.