DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Problem in checkbox

By: rekha singh | 29 Jan 2010 2:40 pm

I want to delete some records through multiple checkboxes.. .
i write a code but it is not working
plz give me some suggestion..

thank in advance.

 

Comments

I designed a website that can send emails to any email server  but i don't know how to recieve emails.  If you know any thing about it then plz help me out & i also have the same problem i want to delete messages by id with check boxes but it is not working .

thanks


 

By: rekha singh | 29 Jan 2010

If you want to try, try use indexing in your id checkbox, and then try use form submit to save it... i suggest you using AJAX for more simple logic & coding :)

hope can help...


 

By: rekha singh | 29 Jan 2010

 

Hi,
in form use [] after the variable name to get the selected values

eg:

html:

<input name="records[ ]" type="checkbox" value="12" />
<input name="records[ ]" type="checkbox" value="17" />
<input name="records[ ]" type="checkbox" value="33" />
<input name="records[ ]" type="checkbox" value="32" />

phpcode:

$records = isset($_POST[ 'records' ])? $_POST['records' ]: ''; // this will
return an array

if (count($records) >0){

$records = implode($records, ','); // will result in string value of
12,17,33,32
$deletesql = 'Delete * from mytable where recordids in (' . $records .')';

}

you may need to do your validations in the above code.

hope this helps!!!
 

By: rekha singh | 29 Jan 2010

Hello,

Hope that this will be helpful for others too

edit and use

------------ --------- --------- --------- --------- --------- -
if(isset($_POST[ checkbox] ) && $_POST[checkbox] != NULL )
                     {
                    foreach($_POST[ 'checkbox' ] as $key=>$id)
                     {
                             
                           
                            $prod_id = $_POST['id'] [$key];
                           
                            $QRY_Del="DELETE FROM table WHERE Pid='$prod_id' '";
                           
                            $Res=mysql_query( $QRY_Del) ;
           
                   
                     }
                     
                     }
                    

Thanks,

 

By: rekha singh | 29 Jan 2010

you just need to make checkbox field name with array symbol "[]"
$CNT = COUNT($_REQUEST[ 'CHECKBOX NAME']);
FOR($I=0;$I< $CNT;$I++ ) {
  ECHO $_REQUEST[CHECKBOX NAME][$I];
OR DO ANY THING HERE LIKE ADD EDIT OR DELITE
}
TRY IT I THINK YOUR PROBLEM IS SOLVE

 

By: rekha singh | 29 Jan 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move