Añadir y eliminar contactos problema

Iniciado por den_22, 30 Abril 2010, 21:17 PM

0 Miembros y 1 Visitante están viendo este tema.

den_22

Hola que tal, veran estoy haciendo un eliminar y mostrar contactos de cada usuario; el problema que me surge es que me muestra todas los usuarios que hay; y el $cnt me dice por ejemplo tienes 3 usuarios, todo bien, pero en la lista salen todos los que hay y no esos 3.
Tampoco se eliminan los usuarios que uno quiere eliminar.
Dejo el codigo por las dudas.

Código (php) [Seleccionar]
<?php
 error_reporting
(E_ALL E_NOTICE);
session_name('pLogin');
session_set_cookie_params(2*7*24*60*60);
session_start();
include(
"connect.php");

$usuario=$_SESSION['usuario'];
$tid=$_GET["id"];
$id=$_SESSION["id"];

$msg1="";
$to_delete="";
$items_removed=0;
if ( 
count($_POST)<>)
{
/////////////////////////// A REQUEST TO DELETE SOME CONTACTS ///////////////

for($i=1;$i<=$_REQUEST["cnt"];$i++)
{
 
if ( isset(
$_REQUEST["checkbox" $i]) )  //Is the checkbox ticked
{
if (
$to_delete!="") { $to_delete.="," ; }  //To insert comma??
$to_delete.= $_REQUEST["checkbox" $i];  //Add another item to delete
$items_removed++;
}

//End For
if ($to_delete=="")
{
$msg1=" No se puede eliminar ningun usuario de la lista de contactos ";
}
else
{
$del_str="  Delete from dm_contacts where dm_contact_id IN (" $to_delete .")";
mysql_query($del_str);
$msg1= ($items_removed 1)?$items_removed " Usuarios que han sido removidos de tu lista de contactos":$items_removed " El usuario ha sido removido de tu lista";
}
header("Location:"." msg_confirm_mem.php?errmsg=".urlencode($msg1));
die();
/////////////////////////////CONTACTS HAVE BEEN REMOVED /////////////////////
}



$rs0_query=mysql_query("Select count(*) from dm_contacts  where  dm_uid =" .$tid );
$rs0=mysql_fetch_array($rs0_query);
$contact_count=$rs0[0];

$rs0_query=mysql_query("SELECT * FROM dm_contacts, members WHERE dm_contacts.dm_contact_id=members.id" );
?>

<script language="javascript">
function validate(form)
{
if((form.username.value==""))
{
alert('Por favor especifica un nombre de usuario');
form.username.focus();
return false;
}
return true;
}
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" >
  <tr>
    <td colspan="3" valign="top"><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="titlestyle">&nbsp;Añadir a mi lista de contactos</td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td><table width="100%" border="0" align="center" cellpadding="2" cellspacing="5" class="onepxtable">
              <form name="form1" method="post" action="addcontact.php" onSubmit="return validate(this);">
                <tr valign="top">
                  <td width="40%" align="right" class="innertablestyle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr align="right">
                        <td width="60%"><font class="normal"><strong><font class='normal'>
                          </font></strong></font></td>
                        <td><font class="normal"><strong><font class='normal'>Username</font></strong></font></td>
                      </tr>
                    </table></td>
                  <td width="6">&nbsp;</td>
                  <td width="60%"><font face="Arial, Helvetica, sans-serif" size="2">
                    <input type="text" name="username">
                    </font></td>
                </tr>
                <tr valign="top">
                  <td align="right" class="innertablestyle">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td><input type="submit" name="Submit2" value="Add User"></td>
                </tr>
              </form>
            </table></td>
        </tr>
      </table>
     
    </td>
  </tr>
  <tr>
    <td height="25" colspan="3" valign="middle"> <div align="center"><font class='red'>
        </font></div></td>
  </tr>
  <tr>
    <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td valign="top"> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="onepxtable">
              <tr >
                <td valign="top"> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="0" class="innertablestyle">
                    <tr>
                      <td height="25" class="titlestyle">&nbsp;Mis contactos</td>
                    </tr>
                    <tr>
                      <td height="25" valign="middle"><font class='normal'>Tu lista de contactos tiene <strong><font class='red'><?php echo $contact_count?></font></strong><?php
if( $contact_count>1)
{
echo " usuarios";
}
else
{
echo " usuario";
}
?>
</font><font class='red'><br>
                        </font></td>
                    </tr>
                    <tr>
                      <td height="25" valign="middle"><font class='normal'>To
                        remove a user from my contacts list just check the check
                        box and click the remove button below.</font></td>
                    </tr>
                    <tr>
                      <td valign="top">
  <script language="javascript">
//<!--
function select_all()
{
  for (var i=0;i<document.form2.elements.length;i++)
  {
var e =document. form2.elements[i];
if ((e.name != 'check_all') && (e.type=='checkbox'))
{
   e.checked = document.form2.check_all.checked;
}
  }
}
function validate_rem(form)
{
var checked='no';
  for (var i=0;i<form.elements.length;i++)
  {
var e =form.elements[i];
if (e.checked==true)
{
   checked='yes';
}
  }
if(checked=='no')
{
alert('Por favor elige al menos un contacto a eliminar');
return false;
}
return true;
}
//-->
</script>
<form name="form2" method="post" action="mostrarcontactos.php" onSubmit="return validate_rem(this);">
                          <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1">
                            <tr class="subtitle">
                              <td width="10" align="right"> <input name="check_all" type="checkbox" id="check_all" onClick="select_all();" value="yes"></td>
                              <td height="25"><b><font class='normal'>Usuario</font></b></td>
                              <!--td><b><font class='normal'>Company Name </font></b></td>
                              <td><b><font class='normal'>Phone</font></b></td>
                              <td><b><font class='normal'>Fax</font></b></td-->
                            </tr>
                            <?php
$cnt=0;
while ($rs0=mysql_fetch_array($rs0_query))
{
  $cnt++;

  
  
?>

                            <tr>
                              <td width="10" align="right" ><font class='normal'>
                                <input type="checkbox" name="checkbox<?php echo $cnt;?>" value="<?php
   echo $rs0["dm_uid"];?>
">
                                </font></td>
                              <td ><font class='normal'><a href="replyuser.php?type=contact&tid=<?php echo $rs0["dm_contact_id"];?>" ><?php echo $rs0["usuario"];?></a>
                                </font></td>

                            </tr>
                            <?php
}
?>

                            <tr >
                              <td colspan="2" align="left"> <input type="hidden" name="cnt" value="<?php echo $cnt?>">
                                <input type="submit" name="Submit3" value="Remove">
                              </td>
                              <!--td>&nbsp;</td>
                              <td>&nbsp;</td>
                              <td>&nbsp;</td-->
                            </tr>
                          </table>
                        </form></td>
                    </tr>
                  </table></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
</table>


el dm_uid-> es la id del usuario de la sesion
el dm_contacts_id-> es la id del contacto añadido.


Gracias de antemano