Basically my form will have to add credits to the registered users that was checked in the table that was loaded in the page. When the user clicks the submit button, the registered users which are checked will have an additional credits. My problem is that I don’t know how to retrieve the rows that are checked in the looped table. Here is my code.
<form name="blah" method="POST" action="">
<?php
include("mysql_config.php");
// INITIAL OUTPUT WHEN THE PAGE IS LOADED
echo "<table class='sample'><tr>
<td></td>
<td><b>User ID</b></td>
<td><b>Username</b></td>
<td><b>First Name</b></td>
<td><b>Last Name</b></td>
<td><b>Credits</b></td>
</tr>";
$q = "SELECT * FROM users_credits";
$res = mysql_query($q);
$num_rows = mysql_num_rows($res);
for($i=0; $i<$num_rows; $i++){
$db_field = mysql_fetch_assoc($res);
$reg_id = $db_field['reg_id'];
$credits = $db_field['credits'];
$q2 = "SELECT username, fn, ln FROM reg_users WHERE reg_id = $reg_id";
$res2 = mysql_query($q2);
$db_field2 = mysql_fetch_assoc($res2);
$username = $db_field2['username'];
$fn = $db_field2['fn'];
$ln = $db_field2['ln'];
echo "<tr>
<td><input type='checkbox' value='$i' name='add_credit'></td>
<td>$reg_id</td>
<td>$username</td>
<td>$fn</td>
<td>$ln</td>
<td>$credits</td>
</tr>";
}
?>
<input type="submit" name="save" value="Save" >
</form>
Thanks in advance to the persons who’ll help me. 🙂
Please update your page as :
Make the form action in update.php as
Here you will get the users id in array.