Forum Moderators: coopster
I need a PHP that outputs a simple HTML form with a list of all the members (and their name and email) in the DB, with a checkbox next to each. This form must be specific to whomever is logged on, such that the data (s)he enters only goes into the relevant row, column or table of the individual whose checkbox was checked.
Summing up: I need a way for
(1) a form to display all the listed members in a MySQL DB and
(2) to have the info selected in the form entered into the relevant row, table, or column of the individual selected.
I'm not asking for anyone to write me code, just pointers on either 1 or 2; I'm a newbie so a pointer is what I need.
Thanks, the little help I've asked for in the past has gotten me a long way.
<?php
// Let's assume you have a DB connection and database selected under the variable $conn// Define array for unique user id storage
$userIDs = array();// Output form
echo '<form name="myForm" action="check.php" method="post">';//Query the database for user data
$query = mysql_query("SELECT * FROM users", $conn);
while ($user = mysql_fetch_array($query))
{
// Populate array
$userIDs[] = $user['user_id'];
// Output checkboxes
echo '<input name="check_' . $user['user_id'] . '" type="checkbox" value="yes" /><br />';
}// check if form has been submitted
if (isset($_POST['submit']))
{
// check user id array for checked values
foreach ($userIDs as $key=>$id)
{
if (isset($_POST['check_' . $id]))
{
// Take whatever action based on $id variable
}
}
}// end form
echo '<input type"submit" name="submit" value="submit" /></form>';
?>
Basically when your loop gets the database information it also populates an array of user id's which you can then use later on in the script to check whether those particular checkboxes have been ticked.