473,795 Members | 2,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checked(checkbo x) row or rows to be deleted when button(delete) is clicked

27 New Member
Hi all,
I am new to php,my question is that in this following code i am retrieving many rows from the database which is working good.i want to delete a particular row(s) which is checked(checkbo x) and this should be done when the deletecontact button is clicked and also should be deleted int the database also

Somebody help me out on this code

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function SetAllCheckBoxes(FormName, FieldName, CheckValue)
  5. {
  6.     if(!document.forms[FormName])
  7.         return;
  8.     var objCheckBoxes = document.forms[FormName].elements[FieldName];
  9.     if(!objCheckBoxes)
  10.         return;
  11.     var countCheckBoxes = objCheckBoxes.length;
  12.     if(!countCheckBoxes)
  13.         objCheckBoxes.checked = CheckValue;
  14.     else
  15.         // set the check value for all check boxes
  16. for(var i = 0; i < countCheckBoxes; i++)
  17.  
  18.             objCheckBoxes[i].checked = CheckValue;
  19. }
  20. </script>
  21. </head>
  22. <body>
  23.  
  24. <?php include "menu.php";?>
  25.  
  26. <center><b>CONTACT INFO</b></center><br>
  27.  
  28.   <form method="post" onSubmit="<?=$PHP_SELF?>">
  29.  
  30.  <table border="0" cellpadding="0" cellspacing="0">
  31.  
  32.   <tr>
  33.     <td>
  34.         <table  border="0" cellpadding="0" cellspacing="0">
  35.             <tr>
  36.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="createcontact.php" style="text-decoration:none"><input type="button" name="new" value="CREATE CONTACT"  style="width:170px;background-image:url(pink.gif)"></a></td>
  37.                 <td style="padding-left:20px;padding-bottom:20px;"><a href="createlead.php" style="text-decoration:none"><input type="button" name="new" value="CREATE LEAD"  style="width:170px;background-image:url(pink.gif)"></a></td>
  38.             </tr>
  39.  
  40.             <tr>
  41.                 <td style="padding-left:20px;"><a href="createaccount.php" style="text-decoration:none"> <input type="button" name="new" value="CREATE ACCOUNT"  style="width:170px;background-image:url(pink.gif)"></a></td>
  42.                 <td style="padding-left:20px;"> <a href="createopportunity.php" style="text-decoration:none"> <input type="button" name="new" value="CREATE OPPORTUNITY"  style="width:170px;background-image:url(pink.gif)"></a></td>
  43.             </tr>
  44.         </table>
  45.     </td>
  46.  
  47.     <td style="padding-left:120px;">
  48.         <table  cellpadding="8" cellspacing="0" with frame="box">        
  49.         <tr>
  50.             <td style="padding-left:10px;padding-bottom:20px;">LAST NAME</td>
  51.             <td style="padding-left:60px;padding-bottom:20px;"><input type="text" name="lname"></td>
  52.         </tr>
  53.  
  54.         <tr>
  55.             <td style="padding-left:10px"><input type="submit" name="search" value="SEARCH"  style="width:80px;background-image:url(pink.gif)" ></td>
  56.             <td style="padding-left:30px"><input type="reset" name="clear" value="CLEAR"  style="width:80px;background-image:url(pink.gif)" ></td>
  57.         </tr>
  58.         </table>
  59.     </td>
  60.   </tr>
  61. </table>
  62. <br/><br/>
  63.  
  64. <b><center>CONTACT LIST </center></b>
  65.  
  66. <br/>
  67.  
  68.  <?php
  69.      include 'connect.php';
  70.      $a= $_POST[lname];
  71.  
  72.  if(!$a==NULL)
  73. {
  74.     $res = mysql_query("SELECT * FROM createcontact where lname LIKE '%$a%' ");
  75. ?>   
  76.  
  77.    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  78.     <input type="button"  style="width:130px;background-image:url(pink.gif)" onclick="SetAllCheckBoxes('contacts', 'myCheckbox', true);" value="SELECT ALL">
  79.  
  80. <input type="button" style="width:130px;background-image:url(pink.gif)"onclick="SetAllCheckBoxes('contacts', 'myCheckbox', false);" value="SELECT NONE">
  81.   <input type="button" name="delete" value="DELETE CONTACT"  style="width:130px;background-image:url(pink.gif)">
  82.  
  83.    </form>
  84.     <table border="1" align="center" cellpadding="0" cellspacing="0" width="900" style="border:1px solid #ffaacc;">        <tr>
  85.         <td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox" name="myCheckbox"></td>
  86.         <td>NAME</td>
  87.         <td>TITLE</td>
  88.         <td>A/C NAME</td>
  89.         <td>EMAIL</td>
  90.         <td>PHONE NO</td>
  91.         <td>TEAM</td>
  92.         <td>USER</td>
  93.     </tr>
  94.  
  95.     <?
  96.     while($row = mysql_fetch_array($res))
  97.    {
  98.  
  99.     echo '<tr>';
  100.     echo '<td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox" name="myCheckbox"></td>';
  101.     echo '<td >'.$row['lname'].'</td>';
  102.     echo '<td >'.$row['title'].'</td>';
  103.     echo '<td >'.$row['acname'].'</td>';
  104.     echo '<td >'.$row['email'].'</td>';
  105.     echo '<td >'.$row['phone'].'</td>';
  106.     echo '<td >'.$row['team'].'</td>';
  107.     echo '<td >'.$row['assignedto'].'</td>';
  108.     echo '</tr>';
  109.  
  110.    }
  111.  
  112.    echo "</table>";
  113. }
  114. else
  115. {
  116.  
  117.     $res = mysql_query("SELECT * FROM createcontact ");
  118. ?>
  119.  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  120.     <input type="button"  style="width:130px;background-image:url(pink.gif)" onclick="SetAllCheckBoxes('contacts', 'myCheckbox', true);" value="SELECT ALL">
  121.  
  122. <input type="button" style="width:130px;background-image:url(pink.gif)"onclick="SetAllCheckBoxes('contacts', 'myCheckbox', false);" value="SELECT NONE">
  123.   <input type="button" name="delete" value="DELETE CONTACT"  style="width:130px;background-image:url(pink.gif)">
  124. </form>
  125.  
  126.  
  127.  <table border="1" align="center" cellpadding="0" cellspacing="0" width="900" style="border:1px solid #ffaacc;">        <tr>
  128.  
  129.  <td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox"  name="myCheckbox"></td>
  130.  
  131.         <td>NAME</td>
  132.         <td>TITLE</td>
  133.         <td>A/C NAME</td>
  134.         <td>EMAIL</td>
  135.         <td>PHONE NO</td>
  136.         <td>TEAM</td>
  137.         <td>USER</td>
  138.     </tr>
  139.  
  140. </body> 
  141.     <?
  142.     while($row = mysql_fetch_array($res))
  143.    {
  144.  
  145.     echo "<tr>";
  146.     echo '<td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox" name="myCheckbox"></td>';
  147.     echo "<td>".$row['lname']."</td>";
  148.     echo "<td>".$row['title']."</td>";
  149.     echo "<td>".$row['acname']."</td>";
  150.     echo "<td>".$row['email']."</td>";
  151.     echo "<td>".$row['phone']."</td>";
  152.     echo "<td>".$row['team']."</td>";
  153.     echo "<td>".$row['assignedto']."</td>";
  154.     echo "</tr>";
  155.  
  156.  
  157.    }
  158.  
  159.     echo"</table>";?>
  160.  
  161. <?
  162.     }    
  163. ?>
  164.  
  165. </form>
  166. </body>
  167. </html>
  168.  
  169.  
  170.  
Mar 26 '09 #1
1 4163
Markus
6,050 Recognized Expert Expert
If you have multiple checkboxes on the same subject, you need to pass them as an array. You do this by appending brackets to the end of all the checkboxes name's. <input type="checkbox" name="delete_it ems[]" value="1" />

-- Assumes you're using POST --

Then, in PHP, you can traverse the array of selected checkboxes (if it exists) and perform actions on them accordingly.

Expand|Select|Wrap|Line Numbers
  1.  
  2. if ( count ( $_POST['delete_items'] ) > 0 )
  3. {
  4.     foreach ( $_POST['delete_items'] as $key => $val )
  5.     {
  6.         echo "{$key} -> {$val}<br />";
  7.     }
  8. }
  9. else
  10. {
  11.     echo "No checkboxes passed.";
  12. }
  13.  
Mar 26 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2976
by: Bart Verbeke | last post by:
Hi, I have a form with 2 radio buttons (ACCEPT/REJECT). When the page is initially loaded, no textbox should be visible. When a user clicks the REJECT radio button, a textbox should automatically appear below the radiobutton where the user can motivate why he chose the reject option (which we require). When the user clicks the ACCEPT radio button, the textbox should not
4
26988
by: Piotr | last post by:
how can I read (in alert for example) array index number of checked checkbox? I have: <input type="checkbox" id="id_number" name="check" value="1" onclick="show()"/> <input type="checkbox" id="id_number" name="check" value="2" onclick="show()"/> <input type="checkbox" id="id_number" name="check" value="3"
0
1288
by: L Mehl | last post by:
Hello -- My form's cmdCancel button requires 3 clicks before the code in Cancel_Click fires. Each click prior to that success moves the highlight to the next field in the Tab order . I placed a Breakpoint on the first command in the Click event ot cmdCancel. It is hit after that third click of cmdCancel.
2
2089
by: Alan Silver | last post by:
Hello, I have a repeater with a list of products in it. Each item in the repeater has a checkbox, allowing the product to be selected. When a link button is clicked, I want to loop through the repeater and handle each product whose checkbox is checked. The repeater looks (greatly chopped down) like this... <asp:Repeater ID="rptProducts" RunAt="Server">
5
2670
by: tsnyder | last post by:
I need to have an option button that allows editing to a field only when it is checked.
0
1799
by: rn5a | last post by:
All the rows in a DataGrid are accompanied by a CheckBox. When a user checks the rows & clicks a Button, the checked rows get deleted. For e.g. assume that the DataGrid displays 10 rows. A user checks the rows 2, 4, 6, 8 & 10. When he clicks the Button, the page posts & the next page displays only 5 rows i.e. row 1, 3, 5, 7 & 9. The checked rows are populated in a ViewState variable & will have values like 2, 4, 6, 8, 10, (note that there...
10
18939
by: Bishman | last post by:
Hi, I need to programmatically allow or disallow the selection of multiple checkboxes on a form . At certain times I only want to allow a single selection, at other times I may wish to allow multiple. Is there a way of doing this ? I dont want to use Radio buttons..... Thanks,
2
3990
by: arizal | last post by:
Hi, I am having some problem trying to think how to write a code for deleting the entry which is loaded from the database. I have a while loop which pulls the userID, name etc from the database and i have a checkbox next to each useriD. I also have a Delete button. SO what i want is when delete is clicked it will delete all items which are checked. My code <?php $a=0; $i=0; While ($row =mysql_fetch_array($rs)) { $currentCom_id =...
0
4102
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I overcame. Now the second part is my new problem is that I want that the next time that page loads for...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.