I am trying to create a list of users that hasn't been activated and have checkboxes next to them to that will let me select users and then activated them.
In the mysql table, teh field 'status' (type int) holds that data. If it is '1', then the user isn't active, if it is '2', then the user has been activated.
I want to be able to select multiple checkboxes (aka multiple users) and activate them all at once (the checkboxes, using a while loop, hold their userid. How can I do this? The code I have currently (uncomplete) is below.
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td> </td>
<td align="center" valign="top">Name</td>
<td align="center" valign="top">Type</td>
<td align="center" valign="top">Age</td>
<td align="center" valign="top">Registered On</td>
<td align="center" valign="top">Country</td>
<td align="center" valign="top">Email</td>
</tr>';
$sql = "SELECT userid, first_name, last_name, type, ";
$sql .= "DATE_FORMAT(dob, '%Y') AS dob, DATE_FORMAT(date_registered, '%m/%d/%Y') AS date_registered, ";
$sql .= "country, email FROM users WHERE status = 1 ORDER BY date_registered DESC";
$query = mysql_query($sql) or die(sql_error());
if(mysql_num_rows($query) > 0)
{
$currentdate = getdate();
$year = $currentdate["year"];
while($row = mysql_fetch_array($query))
{
$age = $year - $row['dob'];
echo '<tr>
<td><input name="select_user" type="checkbox" id="select_user" value="' . $row['userid'] . '"></td>
<td align="center" valign="top">' . $row['first_name'] . ' ' . $row['last_name'] .'</td>
<td align="center" valign="top">' . $row['type'] . '</td>
<td align="center" valign="top">' . $age . '</td>
<td align="center" valign="top">' . $row['date_registered'] . '</td>
<td align="center" valign="top">' . $row['country'] . '</td>
<td align="center" valign="top">' . $row['email'] . '</td>
</tr>';
}
echo '<tr><td><input name="submit" type="submit" value="Activate"></td></tr></table></form>';
}
else
{
echo 'There are no users that need to be registered.';
}
As you can see, it gets data from the table, loops it to get multiple records but I don't know how to activate multiple accounts at once.
I would try this but don't know how to complete it:
UPDATE users SET status = '2' WHERE userid = '????"
What would I put in the ??? because there would be more than one userid? Thanks for any help.