karthika pommudu

karthika pommudu

  • NA
  • 321
  • 35k

While loop values pass to php update query by submit button

Jul 24 2020 4:07 AM
Hi all,Here my code by use while loop I will show the access number values in form after edit the field name="veh_nos_a"  I wanna pass the values into update query via the submit button.
Anyone help to clear this.
have a good day! 
 
While loop code: 
  1. $result2=$link->query("SELECT * FROM `Access_card` where unitentry='$unit_no'");       
  2.                                                     echo   $result11 = mysqli_query($link,$result2);  
  3.                                                   $row = mysqli_fetch_array($result11,MYSQLI_ASSOC);  
  4.                                                    
  5.    
  6.   
  7.                              while ($row = $result2->fetch_assoc())   
  8.                                             {  
  9.                                 $accessnum = $row['accessnum'];                
  10.                       
  11.                                                 ?> <div class="row">         
  12.                                                     <div class="col-sm-6">  
  13.                                                      <label>Access card number</label>  
  14.                                                        <input type="text" name="veh_nos_a" id ='accessnum' value="<?php echo $accessnum; ?>">         
  15.                                                           </div>                                                                
  16.                                                         </div>  
  17.                                                         <?  
  18.                                             }  
  19.                                             ?>  
  20.                                                 <div class="col-sm-5">  
  21.                              <span class="fw-separator"></span>  
  22.                              <input type="submit" class="previous-form action-button  color-bg" name="paym">  
  23.                         </div>   
 Update query:
  1.     if(isset($_POST['paym']))  
  2.     {  
  3.       
  4. $access = mysqli_real_escape_string($link, $_POST['veh_nos_a']);  
  5.   
  6.   
  7. echo $access;   
  8.       
  9. for($count = 0; $count<count($access); $count++)  
  10. {  
  11.    
  12.  echo $access;   
  13.   
  14.    
  15. }   
  16.   
  17. $result1="UPDATE `res_veh` SET `unit_no` = '$unit_no', access='$acess ' WHERE unit_no = '$unit_no'";  
  18.       
  19.       
  20.       
  21. if ($link->query($result1) === TRUE)   
  22. {  
  23.   echo "Record updated successfully";  
  24. else {  
  25.   echo "Error updating record: " . $link->error;  
  26. }  
  27.     }     
  28.     else   
  29.     {  
  30.         echo 'error';  
  31.     }