#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    34
    Rep Power
    3

    Displaying Multiple Rows But Update One Row


    I have a page where I'm displaying multiple records from one table. For each record I have a few fields I won't to update per each row. I can't seem to get the update code to work. Please provide any assistance.

    PHP Code:
    <form name="drugs" method = "post" action="">
                     <table style='width: 95%;' >
                        <?php
                        $query2 
    mysql_query("Select * from rxprescriptions where rx_id = $rx_id");
                        while(
    $row mysql_fetch_array($query2))
                        {
                        
    ?>
                        <tr>
                        <td><b>Drug</b></td>
                        <td style="width: 146px"><b>How Often</b></td>
                        <td><b>Comments</b></td>
                        <td><b>Filled</b></td>
                        <td><b>MR Upd</b></td>
                         <td style="width: 82px"><strong>Complete</strong></td>
                        <td style="width: 143px"><b>Cancel</b></td>
                       </tr>
                        <tr>
                        <td style="width: 218px" valign="top"><?php echo $row['rxp_name']; ?></td>
                       <td style="width: 146px" valign="top"><?php echo $row['rxp_howoften']; ?></td>
                         <td style="width: 150px"><textarea name='' rows='5' cols='40'><?php echo $row['rxp_comments']; ?></textarea></td>
                         <td class="style4"><input name="rxp_filled" type="checkbox" <?php if($rxp_filled): ?>checked="checked"<?php endif; ?>/></td>
                         <td class="style4"><input name="rxp_mr_upd" type="checkbox" <?php if($rxp_mr_upd): ?>checked="checked"<?php endif; ?>/></td>
                         <td style="width: 82px"><input type="submit" name="Complete" value="Complete"></td>
                        <td style="width: 143px"><input type="submit" name="Cancel" value="Cancel"></td>
                       </tr>
                      
                        <tr>
                        <td style="width: 218px; height: 23px;"><b>Dosage</b></td>
                       <td style="width: 146px; height: 23px;"><b>Qty</b></td>
                         <td style="width: 150px; height: 23px;"><strong>Instructions</strong></td>
                        <td><?php echo $row['rxp_id']; ?></td>
                          <td></td>
                         <td style="width: 82px; height: 23px;"><b>User Upd</b></td>
                        <td style="width: 143px; height: 23px;"><b>Date Upd</b></td>                   </tr>
                        <tr>
                        <td style="width: 183px"><?php echo $row['rxp_dosage']; ?></td>
                       <td style="width: 146px">&nbsp;</td>
                         <td style="width: 150px"><?php echo $row['rxp_insruct']; ?></td>
                         <td>&nbsp;</td>
                         <td>&nbsp;</td>
                         <td style="width: 82px"><?php echo $row['rxp_usr_upd']; ?></td>
                        <td style="width: 143px"><?php echo $row['rxp_rec_upd']; ?></td>
                                        </tr>
                                         <tr><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td><td><hr></td></tr>
                       <?php
                       
    }
                       
    ?>
                        </table></form><br/>
                        <?php
                        $getdate 
    date("Y") . "-" date("m") . "-" date("d");
                        if (isset(
    $_POST['Called']))
                        {
                        
    $sqlrx "update rxrefill set pt_called = 1, rx_called_date =  '$getdate', rx_status = 'Called' where rxid = $rx_id";
                        
    $resultrx mysql_query($sqlrx);
                        }
                        if(isset(
    $_POST['Complete'])) 
                        {
                        
                        
    $rxcmt $_POST['rxp_comments'];
                        
    $rxuser $_SESSION['valid_user'];
                        
    $rxfilled $_POST['rxp_filled'];
                        
    $rxmrupd $_POST['rxp_mr_upd'];
                         
    $rxpid $_POST['rxpid'];
                        echo 
    "$rxpid - here";
                        
    $sql1="Update rxprescriptions set rxp_comments = '$rxcmt', rxp_usr_upd = '$rxuser', rxp_rec_upd =  '$getdate', rxp_cmpl_can = 'C' where rxp_id = $rxpid";
                        
    $result1=mysql_query($sql1);
                        }
                         if(isset(
    $_POST['Cancel'])) 
                        {
                        
    $rxcmt $_POST['rxp_cmts'];
                        
    $rxuser $_SESSION['valid_user'];
                        
    $rxfilled $_POST['rxp_filled'];
                        
    $rxmrupd $_POST['rxp_mr_upd'];
                        
    $sql1="Update rxprescriptions set rxp_comments = '$rxcmt', rxp_usr_upd = '$rxuser', rxp_rec_upd =  '$getdate', rxp_filled = '$rxfilled', rxp_mr_upd = '$rxmrupd', rxp_cmpl_can = 'X' where rxp_id = $rxpid";
                        
    $result1=mysql_query($sql1);
                        }
                        
    // status entire refill as completed if all drugs have been addressed
                        
    $chkall "Select count(*) from rxprescriptions where rx_id = $rx_id and isnull(rxp_cmpl_can)";
                        
    $resultchk mysql_query($chkall);
                        
    $num mysql_result($resultchk,0);
                        if (
    $num == 0)
                        {
                        
    $sqlrx2 "update rxrefill set rx_status = 'Complete' where rxid = $rx_id";
                        
    $resultrx2 mysql_query($sqlrx2);
                        }
                        if(
    $resultrx){
                        echo (
    '<meta http-equiv="refresh" content="0;url=/request_upd.php">');
                        }
                        
    mysql_close();
    So each row has a "Complete" and "Cancel" button where the user can click on it to update the record they have updated. The rxp_id field is a unique (auto_increment) field on the table and want to update the record associated to that id with the three fields they can update within the form.

    Thank you for any assistance in this manner. I know I'm close, but have been struggling.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,619
    Rep Power
    595
    Please edit your post and use [ PHP ] tags for your code. See the sticky at the top of this forum.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. JavaScript is not spelt java
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2011
    Location
    Landan, England
    Posts
    743
    Rep Power
    165
    Where is the variable $rx_id in the 4th line defined? I notice you create another variable named $rxpid much further down the page.. I don't know if this is supposed to be the same thing?

    Your code refers to posted data named 'Called' but the form at the top has a field named 'Complete'..? So I can't quite fathom whether this page is supposed to be submitting to itself, or if there is a second page involved that you haven't shown?!
    PHP Code:
    <form name="drugs" method "post" action=""
    The action parameter should not be empty. It could be "#" but I assume you need to post the data somewhere? If you intend it to post to the same page then I use this:
    PHP Code:
    action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"
    Last edited by AndrewSW; December 18th, 2012 at 03:40 PM.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    34
    Rep Power
    3

    Variables


    The variable $rx_id is one used to update another table. The $rxpid is the variable that I use to read the table I'm having problems updating. The page has 2 forms. Once at the top displays the header record. The second form displays details(xrefs) of the header record and on each record I display the Complete and Cancel buttons. So in my code the "Called" test works, but the Complete and Cancel buttons don't.

    I will try the posted to self on the action, but I don't think this will matter as I'm not getting the data in the "Complete" button test loaded.
    Originally Posted by AndrewSW
    Where is the variable $rx_id in the 4th line defined? I notice you create another variable named $rxpid much further down the page.. I don't know if this is supposed to be the same thing?

    Your code refers to posted data named 'Called' but the form at the top has a field named 'Complete'..? So I can't quite fathom whether this page is supposed to be submitting to itself, or if there is a second page involved that you haven't shown?!
    PHP Code:
    <form name="drugs" method "post" action=""
    The action parameter should not be empty. It could be "#" but I assume you need to post the data somewhere? If you intend it to post to the same page then I use this:
    PHP Code:
    action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"

IMN logo majestic logo threadwatch logo seochat tools logo