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 -
<html>
-
<head>
-
<script type="text/javascript">
-
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
-
{
-
if(!document.forms[FormName])
-
return;
-
var objCheckBoxes = document.forms[FormName].elements[FieldName];
-
if(!objCheckBoxes)
-
return;
-
var countCheckBoxes = objCheckBoxes.length;
-
if(!countCheckBoxes)
-
objCheckBoxes.checked = CheckValue;
-
else
-
// set the check value for all check boxes
-
for(var i = 0; i < countCheckBoxes; i++)
-
-
objCheckBoxes[i].checked = CheckValue;
-
}
-
</script>
-
</head>
-
<body>
-
-
<?php include "menu.php";?>
-
-
<center><b>CONTACT INFO</b></center><br>
-
-
<form method="post" onSubmit="<?=$PHP_SELF?>">
-
-
<table border="0" cellpadding="0" cellspacing="0">
-
-
<tr>
-
<td>
-
<table border="0" cellpadding="0" cellspacing="0">
-
<tr>
-
<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>
-
<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>
-
</tr>
-
-
<tr>
-
<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>
-
<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>
-
</tr>
-
</table>
-
</td>
-
-
<td style="padding-left:120px;">
-
<table cellpadding="8" cellspacing="0" with frame="box">
-
<tr>
-
<td style="padding-left:10px;padding-bottom:20px;">LAST NAME</td>
-
<td style="padding-left:60px;padding-bottom:20px;"><input type="text" name="lname"></td>
-
</tr>
-
-
<tr>
-
<td style="padding-left:10px"><input type="submit" name="search" value="SEARCH" style="width:80px;background-image:url(pink.gif)" ></td>
-
<td style="padding-left:30px"><input type="reset" name="clear" value="CLEAR" style="width:80px;background-image:url(pink.gif)" ></td>
-
</tr>
-
</table>
-
</td>
-
</tr>
-
</table>
-
<br/><br/>
-
-
<b><center>CONTACT LIST </center></b>
-
-
<br/>
-
-
<?php
-
include 'connect.php';
-
$a= $_POST[lname];
-
-
if(!$a==NULL)
-
{
-
$res = mysql_query("SELECT * FROM createcontact where lname LIKE '%$a%' ");
-
?>
-
-
-
<input type="button" style="width:130px;background-image:url(pink.gif)" onclick="SetAllCheckBoxes('contacts', 'myCheckbox', true);" value="SELECT ALL">
-
-
<input type="button" style="width:130px;background-image:url(pink.gif)"onclick="SetAllCheckBoxes('contacts', 'myCheckbox', false);" value="SELECT NONE">
-
<input type="button" name="delete" value="DELETE CONTACT" style="width:130px;background-image:url(pink.gif)">
-
-
</form>
-
<table border="1" align="center" cellpadding="0" cellspacing="0" width="900" style="border:1px solid #ffaacc;"> <tr>
-
<td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox" name="myCheckbox"></td>
-
<td>NAME</td>
-
<td>TITLE</td>
-
<td>A/C NAME</td>
-
<td>EMAIL</td>
-
<td>PHONE NO</td>
-
<td>TEAM</td>
-
<td>USER</td>
-
</tr>
-
-
<?
-
while($row = mysql_fetch_array($res))
-
{
-
-
echo '<tr>';
-
echo '<td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox" name="myCheckbox"></td>';
-
echo '<td >'.$row['lname'].'</td>';
-
echo '<td >'.$row['title'].'</td>';
-
echo '<td >'.$row['acname'].'</td>';
-
echo '<td >'.$row['email'].'</td>';
-
echo '<td >'.$row['phone'].'</td>';
-
echo '<td >'.$row['team'].'</td>';
-
echo '<td >'.$row['assignedto'].'</td>';
-
echo '</tr>';
-
-
}
-
-
echo "</table>";
-
}
-
else
-
{
-
-
$res = mysql_query("SELECT * FROM createcontact ");
-
?>
-
-
<input type="button" style="width:130px;background-image:url(pink.gif)" onclick="SetAllCheckBoxes('contacts', 'myCheckbox', true);" value="SELECT ALL">
-
-
<input type="button" style="width:130px;background-image:url(pink.gif)"onclick="SetAllCheckBoxes('contacts', 'myCheckbox', false);" value="SELECT NONE">
-
<input type="button" name="delete" value="DELETE CONTACT" style="width:130px;background-image:url(pink.gif)">
-
</form>
-
-
-
<table border="1" align="center" cellpadding="0" cellspacing="0" width="900" style="border:1px solid #ffaacc;"> <tr>
-
-
<td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox" name="myCheckbox"></td>
-
-
<td>NAME</td>
-
<td>TITLE</td>
-
<td>A/C NAME</td>
-
<td>EMAIL</td>
-
<td>PHONE NO</td>
-
<td>TEAM</td>
-
<td>USER</td>
-
</tr>
-
-
</body>
-
<?
-
while($row = mysql_fetch_array($res))
-
{
-
-
echo "<tr>";
-
echo '<td width="50" align="center"><form name="contacts" onLoad="return false;"><input type="checkbox" name="myCheckbox"></td>';
-
echo "<td>".$row['lname']."</td>";
-
echo "<td>".$row['title']."</td>";
-
echo "<td>".$row['acname']."</td>";
-
echo "<td>".$row['email']."</td>";
-
echo "<td>".$row['phone']."</td>";
-
echo "<td>".$row['team']."</td>";
-
echo "<td>".$row['assignedto']."</td>";
-
echo "</tr>";
-
-
-
}
-
-
echo"</table>";?>
-
-
<?
-
}
-
?>
-
-
</form>
-
</body>
-
</html>
-
-
-
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. -
-
if ( count ( $_POST['delete_items'] ) > 0 )
-
{
-
foreach ( $_POST['delete_items'] as $key => $val )
-
{
-
echo "{$key} -> {$val}<br />";
-
}
-
}
-
else
-
{
-
echo "No checkboxes passed.";
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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"
|
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.
|
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">
|
by: tsnyder |
last post by:
I need to have an option button that allows editing to a field only
when it is checked.
| |
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...
|
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,
|
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 =...
|
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...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |