Hi, I'm new here and also in php coding... so... help me, please! 🙂
This is my question:
I have a mysql table "users" with my users in;
I have another table with groups;
In my page I get data from users table and I list them: beside every row I put a checkbox so that, if I need, I select all users I want and then... when I Submit form... a query deletes row in the table users (what I checked with checkbox, indeed!)
I use:
for checkboxes (in the 'while' loop extracting data from table):
<input type="checkbox" name="erase[]" value="<?php echo $id; ?>">
and then (for the deleting query):
foreach ($_POST['erase'] as $m_id)
{ mysql_query("DELETE FROM users WHERE id = $m_id"); }
Ok... this works fine... so... my question is...
I wish, in same page, associate users I want to a group that is in my table of groups:
I wish... to have a list box that show me groups in my table... and I made this:
<select name="gruppo" size="1">
<option selected value="">choose
<?php
while ($gruppi = mysql_fetch_array($query_groups)) {
$grup = $gruppi['groupname'];
echo "<OPTION value=".$grup.">".$grup."<br />"; } ?>
</select>
...that works
Now what I need is to put another checkbox beside every user listed to associate it to a group that I choose from list box here above.
So that in the same page I can select users to delete and users to link to a group (selected from listbox) than press Submit button and the game is on!
here I post code of my page:
<?php
include ("../usr_connect_db.php");
include ("area_c_usr_connect_db.php");
$query = mysql_query("SELECT * FROM users WHERE confirmed = '1'");
$query_groups = mysql_query("SELECT groupname FROM usersgroups");
if (!$query) { echo "Non users"; }
else
{
?>
link to a group:
<select name="gruppo" size="1">
<option selected value="">choose a group
<?php
while ($gruppi = mysql_fetch_array($query_groups)) {
$grup = $gruppi['groupname'];
echo "<OPTION value=".$grup.">".$grup."<br />"; } ?>
</select>
<form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF'])) ?>" method="post">
<table id="hor-zebra">
<thead>
<tr>
<th scope="col">delete</th>
<th scope="col">link</th>
<th scope="col">ID</th>
<th scope="col">Nome</th>
<th scope="col">Cognome</th>
<th scope="col">Società </th>
<th scope="col">Indirizzo</th>
<th scope="col">CAP</th>
<th scope="col">Città </th>
<th scope="col">Provincia</th>
<th scope="col">Mail</th>
<th scope="col">Gruppo</th>
</tr>
</thead>
<tbody>
<?php
$contatore=0;
while($row = mysql_fetch_array($query))
{
$contatore++;
$id = $row['id'];
?><tr><td><input type="checkbox" name="erase[]" value="<?php echo $id; ?>"></td><?php
-- here should go checkbox for link to a group---
echo "<td>".$contatore."</td>";
echo "<td>".$row['nome']."</td>";
echo "<td>".$row['cognome']."</td>";
echo "<td>".$row['societa']."</td>";
echo "<td>".$row['indirizzo']."</td>";
echo "<td>".$row['cap']."</td>";
echo "<td>".$row['citta']."</td>";
echo "<td>".$row['provincia']."</td>";
echo "<td>".$row['mail']."</td>";
echo "<td>".$row['gruppo']."</td>";
echo "</tr>";
}
echo "<tr><td><p /><input type='submit' name='Submit' value='delete' class='button' /></td></tr>";
echo "</tbody></table>";
echo "</form>";
}
if (isset($REQUEST['Submit']))
{
foreach ($POST['erase'] as $m_id)
{
mysql_query("DELETE FROM users WHERE id = $m_id");
}
?><META HTTP-EQUIV="REFRESH" CONTENT="1; URL=area_clienti_edit_users.php"><?php
} ?>
Anyone would so nice to help me with some code, plese?