I feel like there is an easy solution to this problem yet I can not figure it out. I am displaying the fields of my database using a while loop. At the end of each while loop is a form input where the admin can approve users. (All approved needs to do is change a 1 to a 2 in the approved column of that specific record).
All of the Approved records get changed instead of the specific one that I want. My question is how can I select and change only one record at a time. (The record in which gets approved). Thank you so much for any help you can provide me.
<?php
//select the database to write to
$unapprovedTeachers = mysql_query("SELECT * FROM members_teachers WHERE approved = '1'", $dbc) or die("Could not select the unapproved teachers at this time.");
//While loop to cycle through the rows
while($row = mysql_fetch_assoc($unapprovedTeachers)){
$teacher_id = $row['id'];
echo $teacher_id;
?>
<ul class="admin-fields">
<?php
foreach($row as $field){
if(empty($field)){
echo "....";
}
print '<li>' .$field.' </li>';
}//End For Each Loop
//print $teacher_id;
?>
</ul>
<footer>
<?php
if(isset($_POST['approve'])){
mysql_query("UPDATE members_teachers SET approved = '2' WHERE id= ".$teacher_id."", $dbc) or die ("Oops something 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>
LIMIT 1;to your update. AndPOSTprocessing is not done inline but on top of the script, before any output so you get a chance to redirect.