sql - Update Single DB Record, Using PHP While Loop -


i feel there easy solution problem yet can not figure out. displaying fields of database using while loop. @ end of each while loop form input admin can approve users. (all approved needs change 1 2 in approved column of specific record).

all of approved records changed instead of specific 1 want. question how can select , change 1 record @ time. (the record in gets approved). thank can provide me.

    <?php       //select database write       $unapprovedteachers = mysql_query("select * members_teachers approved = '1'", $dbc) or die("could not select unapproved teachers @ time.");         //while loop cycle through rows         while($row = mysql_fetch_assoc($unapprovedteachers)){             $teacher_id = $row['id'];             echo $teacher_id;     ?>     <ul class="admin-fields">     <?php         foreach($row $field){             if(empty($field)){                 echo "....";             }             print '<li>' .$field.' </li>';         }//end each loop         //print $teacher_id;       ?>             </ul>     <footer>      <?php         if(isset($_post['approve'])){         mysql_query("update members_teachers set approved = '2' id= ".$teacher_id."", $dbc) or die ("oops went wrong");     }       ?>         <ul>             <li>                 <form method="post">                         <button name="approve" id="approve" type="submit">approve</button>                 </form>                </li>        </ul>    </footer>    <!--end new row-->   </section>       <?php     }//end while lopp     mysql_close($dbc);        ?>    </div> 

you're outputting same form every row of data display. need @ least embed id of relevant member inside each form, form can submit specific id, e.g.

<form method="post">         <input type="hidden" name="teacher_id" value="$teacher_id" />         <button name="approve" id="approve" type="submit">approve</button> </form> 

note hidden field. when button gets submitted, can

$teacher_id = $_post['teacher_id'];

to retrieve id, issue update query.


Comments