FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


ned help to delete the selected checkbox





glena
i having trouble deleting the selected checkbox... can someone help me with this?? i think it neds a javascript to check all the selected.. please help me with these,..



thanks...
woodenbrick
You need to be a bit more clear about what you want, post some code up or something.
If you are wondering how to make a checkbox checked:
Code:
<input type="checkbox" name="commentnotify" checked>Comment Notification<br />

if you want it unchecked just dont write the 'checked' part.
glena
thats not wat i men.. i men that if you wil check 2 check box those 2 will be deleted.. how can i check how many checkbox is selected and how to delete it using php
glena
this is what i men for exmple i have 5 checkboxes:

_john
*philip
_edwin
*mark
_leo

i check philip and mark and press the button delete.. i tried it but only philip was deleted. how can i delete those two that i checked an if i check the check all how can i force all to have check and delete all?


please help me with this..
imagefree
glena wrote:
this is what i men for exmple i have 5 checkboxes:

_john
*philip
_edwin
*mark
_leo

i check philip and mark and press the button delete.. i tried it but only philip was deleted. how can i delete those two that i checked an if i check the check all how can i force all to have check and delete all?


please help me with this..


if you did it earlier (even not correctly), and the script is in php, i may be able to help you modify it if you provide the script here.
glena
i dont how to code it i know only how to delete 1 entry but wen it comes to 2 or more selected in the checkbox i dont know how.. please help me code it
sonam
In most situation I am using sessions for switching but you must have different names for each checkbox. For example:

On very top of your page:
Code:
<?php
session_start();

if(@$_SESSION['phil'] == "checked") {
   $phil = "";
} else {
   $phil = "Phil: <input type=\"checkbox\" name=\"phil\" value=\"checkbox\" />";
}
if(@$_SESSION['john'] == "checked") {
   $john = "";
} else {
   $john = "John: <input type=\"checkbox\" name=\"john\" value=\"checkbox\" />";
}
if(@$_SESSION['edwin'] == "checked") {
   $edwin = "";
} else {
   $edwin = "Edwin: <input type=\"checkbox\" name=\"edwin\" value=\"checkbox\" />";
}
?>


Form in html:

Code:
<form name="form1" method="post" action="delete.php">
<?php
echo $phil . "<br />" . $john . "<br />" . $edwin;
?>
<br />
<input type="submit" name="delete" value="Delete" />
</form>


and delete.php :

Code:
<?php
session_start();
$return = "whereIsForm.php";
foreach($_POST as $key => $val) {
   if($val == "checkbox") {
      $_SESSION[$key] = "checked"; 
   }
}
header("Location:$return");
exit;
?>


This is one simple way for your needs. When user close browser and open it again he/she will get back all users.

Sonam
glena
how about when you want to check all the checkbox?? do you have a code?? i think its a javascript but i dont know how to combine the two
sonam
Quote:
how about when you want to check all the checkbox?? do you have a code?? i think its a javascript but i dont know how to combine the two


You can create and delete cehckboxes as many you want. If you check all at once script will delete all. You don't need any JS. Little bit is different if you want to delete full form on the end (after all checkboxes). This is also possible, but you didn't ask. Very Happy

Sonam
glena
how can i do that?? please help me... and if i want to put check all how can i code it?


thanks for helping me.. i hope you could help me with this
sonam
Quote:
how can i do that?? please help me... and if i want to put check all how can i code it?


Can you tell me what do you exactly need. It is not the same coding one "Delete" button or one "Select all" button. Did you need both? Did you like to delete form after all, etc.

Sonam
glena
i want to have a select all checkbox when i check it all the other checkbox will be check and then when i click the delete button it will delete all from the data base. when i dont check the select all checkb0x and i will only check 2 checkbox and click the delete button only those who has a check will only be deleted...

can you help me with this?
rvec
from the database? If you want that you need to give a bit more info. And what if they are all deleted should they be showed the next time (so you can enable them again) or should they just be gone?

I understand you want 5 checkboxes, a "select all" button and a "delete selected" button. If a user deletes 2 should he see 3 or 5 checkboxes after he refreshes?
sonam
Quote:
i want to have a select all checkbox when i check it all the other checkbox will be check and then when i click the delete button it will delete all from the data base.


This is something more different from your first question. Shocked What type of DB you are using?

Sonam
glena
i mean like this one i wrote it but its lacking select all checkb0x if you could help me code it please help me.. this is my code

show contacts
Code:
<table width = '100%'>

<?php
$con = mysql_connect("localhost","root","") or die(mysql_error());
$dbsae = mysql_select_db("contacts");
$sql_query = "SELECT * from tinfos";
$result = mysql_query($sql_query);
while($row = mysql_fetch_array($result)){
?>
<form id="form" name="form" method="post" action="deletecontacts.php">
<tr>

    <td><b> <?php echo $row['fname'] ?> </td>
   <td><b> <?php echo $row['lname'] ?> </td>
   <td><b> <?php echo $row['dobm'] ?> </td>
   <td><b> <?php echo $row['dobd'] ?> </td>
   <td><b> <?php echo $row['doby'] ?> </td>
   <td><b> <?php echo $row['gender'] ?></td>
   <td><b> <?php echo $row['pnum'] ?> </td>
   <td><b>  <input type="checkbox" name="check[]" id="check[]" value="<?php echo $row['fname'] ?>"/> </td>
    
    
    
<?php } ?>
<input name="delete" type="submit" value="delete" />
        
      </form></tr>
</table>


deletecontacts

Code:
<?php
   $connum = $_GET['connum'];
   $con = mysql_connect("localhost","root","") or die(mysql_error());
   $dbase = mysql_select_db("contacts");
   $sql = "SELECT * from tinfos";
   $result = mysql_query($sql);
   $num = mysql_num_rows($result);
   $delete = $_POST['delete'];
   $check = $_POST['check'];
   
      for ($a = 0; $a <= $num; $a++)
      {
         $del_fname = $check[$a];
         $del = "DELETE from tinfos WHERE fname = '$del_fname'";
         $result = mysql_query($del);
            if ($result)
            {
               header('location: showcontacts.php');
            }
            else
            {
            die(mysql_error());
            }

         
      }
      
   

?>


thanks please help me with this... thanks
woodenbrick
For a check/uncheck all checkbox you will need to use javascript. There is a solution here:
http://www.shawnolson.net/a/639/select-all-checkboxes-in-a-form-with-javascript.html
glena
thanks woden... now im done with this one..
Related topics
Windows Tips&tricks!
.::Avatars::.
Explain your current avatar!
php..free account help
Keyboards Shortcuts
Video Editing Tutorial needed. Paying 800 Fri$
DELETING FILES
ned help i want to learn php
Friendster.com clone??? - ned help
Ned help! very bad!
ned help..
unable to delete ftp accounts
Private message system "delete selected."
Windows shortcuts, must know
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.