mercredi 7 décembre 2016

insert multiple values using checkbox

my project like facebook this is my code i want to retrieve data from table called "join_group" { join group : table has 2 coloumn "group_id & member_id) any profile can see my group if he didnt join he click to join and its insert into database his member id and the group id he joins and each admin retrieve data from table join_group and then add them to table group_member by inserting group_id and member_id

what i need that how to insert multiple user in 1 click ( for example more than 1 user request to join my group) and this my code to retrieve and insert

<?php
$link=mysql_connect("localhost","root","")or die("Can't Connect...");
mysql_select_db("project") or die("Can't Connect to Database...");
$QQ="SELECT m.name AS NAME , jg.m_id AS MID FROM member m , join_group jg WHERE jg.m_id = m.m_id AND jg.group_id ='".$dbgroupid."'";
$query = mysql_query($QQ,$link) or die(mysql_error());
$num=mysql_num_rows($query);
if($num > 0)
{
  echo"<form action=\"groupadmin.php?group_id=".$dbgroupid."\">";
  while($row = mysql_fetch_array($query))
{
    echo "<input type='checkbox' name='join[]' value=".$row['MID']."> ".$row['NAME']."<br>";
}
echo "<button style=\"height:30px\" name=\"submet\" type=\"submit\" class=\"btn btn-info\">
                  <p>add</p></button>";
echo "</form>";
if(isset($_POST['submet']))
{
if(!empty($_POST['join']))
{
    $mid = $checkBox = implode(',', $row['MID']);
    $checkBox = implode(',', $_POST['join']);
    $link=mysql_connect("localhost","root","")or die("Can't Connect...");
    mysql_select_db("project") or die("Can't Connect to Database...");
    $qqq= "INSERT INTO `group_member` VALUES ('$dbgroupid','$mid')";
    mysql_query($qqq,$link) or die(mysql_error());
}
else
{
    echo"No URL Inserted ...!!!";
}
}}?>




Aucun commentaire:

Enregistrer un commentaire