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(checkbox) 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
- <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>