•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 396,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,955 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 306 | Replies: 4
![]() |
•
•
Join Date: May 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
I have checkboxes in my HTML form and i want to delete several records from my database using those checkboxes. I'm quite new to php so I have a dificulty in manipulating the checkboxes. so can anyone help me? thank you!
Example....
I have 5 records and i want to delete two. So i'll check 2 checkboxes and then "submit" it. how do i do this in php? making sure that the records were really deleted in my database.
Example....
I have 5 records and i want to delete two. So i'll check 2 checkboxes and then "submit" it. how do i do this in php? making sure that the records were really deleted in my database.
•
•
Join Date: Apr 2005
Location: New York state
Posts: 453
Reputation:
Rep Power: 5
Solved Threads: 66
html Syntax (Toggle Plain Text)
<input type='checkbox' name='someArray[]' value='1' /> <input type='checkbox' name='someArray[]' value='2' /> <input type='checkbox' name='someArray[]' value='3' />
Then in PHP
php Syntax (Toggle Plain Text)
$someArray = $_REQUEST['someArray']; foreach($someArray as $key=>$someElem){ $query = "DELETE FROM someTable WHERE id = ".$someElem; }
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
•
•
Join Date: May 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
I think something's wrong with this code that i made.....the 1st part is the FORM part, the 2nd part is the PHP part
......................FORM.............
.......................PHP ...................
......................FORM.............
<?php
session_start();
?>
<html>
<body link='000000' vlink='000000' alink='gray' >
<table border='0' width='100%' align='center' bgcolor='ffffff' >
<tr><td></br></td></tr>
<tr>
<td width='25%' valign='bottom'>
<table border='0'>
<tr><td><font face='tahoma' size='4'><a href='home.php' style='text-decoration:none;'>Home</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4' ><a href='createEmp.php' style='text-decoration:none;'>Create Personnel Record</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4' ><a href='search_view5.php' style='text-decoration:none;'>Edit Personnel Record</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4'color='silver'>Delete Personnel Record</font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4' ><a href='search_view3.php' style='text-decoration:none;'>View Personnel Record</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4'><a href='sign.php' style='text-decoration:none;'>Logout</a></font></td></tr>
</table>
</td>
<td><img src='header5.jpg' align='center'/></td>
</tr>
<tr>
<td colspan='2' background='line.jpg' height='8'></td>
</tr>
<tr>
<td colspan='2' background='line2.jpg' height='2'></td>
</tr>
<tr>
<td colspan='2' height='20' valign='top'>
</br> <font face='tahoma' size='5' color='gray'>Search Patient Profile</font>
</br><hr width='30%' align='left' size='3' color='silver'></hr></br></br></br>
<center>
<form action="search_view6.php" method="post" >
<input type="submit" value="choice" />
<input type="text" size='40' maxLength="50" name="choice" />
<select name='choose' >
<option value='name'>Lastname</option>
<option value='id'>Doctor's License</option>
</select>
</form>
</center>
</tr>
<tr>
<td colspan='2' height='220' valign='top'>
<?php
$con=mysql_connect("localhost", "root", "x");
if(!$con)
{
die('could not connect: '. mysql_error());
}
mysql_select_db("clinic", $con);
if($_POST[choice]!=NULL)
{
$_SESSION['var'] = $_POST[choice];
$result=mysql_query("SELECT doc_license, doc_fname, doc_mname, doc_lname FROM doctor where doc_license= '$_POST[choice]' or doc_lname= '$_POST[choice]' ");
$row =mysql_fetch_assoc($result);
if($row!=NULL)
{
echo "<table border='5' align='center' bordercolor='skyblue' bordercolorlight='skyblue' bordercolordark='skyblue' cellpadding='2' cellspacing='0' width='50%'>
<tr>
<th>Doctor's License</th>
<th>Name</th>
<th>Delete</th>
</tr>";
echo "<tr align='center'>";
echo "<td>". $row['doc_license']."</td>";
echo "<td>". $row['doc_fname']." ". $row['doc_mname']." ". $row['doc_lname']."</td>";
echo "<td> <input type=\"checkbox\" name=\"id" . $row[doc_license] . "\" value=\"1\"></td>";
$idList = $sep.$row[id];
$sep = ",";
echo "</tr>";
echo "</table>";
echo "<form action='deleteRec.php' method='post' >
<input type='submit' value='Delete Personnel Record'/>
</form>";
echo "<input type=\"hidden\" name=\"idlist\" value=\"$idList\">";
}
else
{
echo "<center>Sorry, record does not exist...</center>";
}
}
mysql_close($con);
?>
</tr>
<tr>
<td></br></br></br></br></td>
</tr>
<tr>
<td colspan='2' background='line2.jpg' height='2'></td>
</tr>
</table>
</body>
</html>
.......................PHP ...................
<?php
session_start();
$idlist=$_POST['id'];
$con=mysql_connect("localhost", "root", "x");
if(!$con)
{
die('could not connect: '. mysql_error());
}
mysql_select_db("clinic", $con)or die('could not connect: '. mysql_error());
$array_id = explode("," $idlist");
foreach($array_id as $id)
{
if(${"id" . $id} == 1)
{
$result=mysql_query("DELETE * FROM doctor where doc_license= $id ");
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Search Patient Record</title>
</head>
<body link='000000' vlink='000000' alink='gray'>
<table border='0' width='100%' align='right' bgcolor='ffffff'>
<tr><td></br></td></tr>
<tr>
<td width='25%' valign='bottom'>
<table border='0'>
<tr><td><font face='tahoma' size='4'><a href='home.php' style='text-decoration:none;'>Home</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4' ><a href='createEmp.php' style='text-decoration:none;'>Create Personnel Record</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4' ><a href='search_view5.php' style='text-decoration:none;'>Edit Personnel Record</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4'color='silver'>Delete Personnel Record</font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4' ><a href='search_view3.php' style='text-decoration:none;'>View Personnel Record</a></font></td></tr>
<tr><td background='line2.jpg' height='3'></td></tr>
<tr><td><font face='tahoma' size='4'><a href='sign.php' style='text-decoration:none;'>Logout</a></font></td></tr>
</table>
</td>
<td><img src='header5.jpg' align='center'/></td>
</tr>
<tr><td height='10'></td></tr>
<tr>
<td colspan='2' background='line.jpg' height='8'></td>
</tr>
<tr>
<td colspan='2' background='line2.jpg' height='2'></td>
</tr>
<tr>
<td colspan='2' height='220' valign='top'>
</br>
<font face='tahoma' size='5' color='gray'>Record Has Been Deleted!</font>
<br>
</td>
</tr>
<tr>
<td></br></br></br></br></td>
</tr>
<tr>
<td colspan='2' background='line2.jpg' height='2'></td>
</tr>
</table>
</body>
</html>
•
•
Join Date: Apr 2008
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
I have checkboxes in my HTML form and i want to delete several records from my database using those checkboxes. I'm quite new to php so I have a dificulty in manipulating the checkboxes. so can anyone help me? thank you!
Example....
I have 5 records and i want to delete two. So i'll check 2 checkboxes and then "submit" it. how do i do this in php? making sure that the records were really deleted in my database.
Assuming that you have the checkboxes named as deletethis[] where the indexes are the indexes in the table, on submitting the form with check box include a code like this. DeleteFunction is a function which deletes the row with id from a specific table.
php Syntax (Toggle Plain Text)
$chk=$_POST['deletethis']; $iserror=false; for($i=0;$i<count($_POST['deletethis']);$i++){ $result=DeleteFunction(key($chk)); if(!is_numeric($result)){ $iserror=true; break; } next($chk); }
if u having any problems ask
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- php coding for checkboxes (PHP)
- Count number of checkboxes being checked in asp.net (ASP)
- counting checkboxes (ASP.NET)
- How to get value of selected dynamic checkboxes? (ASP.NET)
- checkboxes on continuous forms (Visual Basic 4 / 5 / 6)
- How can I use the Checkboxes into a Tree Control (C++)
Other Threads in the PHP Forum
- Previous Thread: simple problem
- Next Thread: Custom From header when emailing?


Linear Mode