Jump to content

Delete rows using checkbox


Vinsanity

Recommended Posts

Can anyone provide me the sources or codes for the delete function using the checkbox... it can be a very simple delete using checkbox since i m a newbie of php... I got these fields in my database(JobID, JobTitle, JobRequirement, Location, JobStatus and CompanyName) and i wan to delete the certain rows when i checked the row and click on the delete button... Can anybody help me... Any help will be appreciated...
Link to comment
https://forums.phpfreaks.com/topic/34204-delete-rows-using-checkbox/
Share on other sites

There are several topics posted about this already, you should search the forum...

But, to get you started:

create a checkbox, the value of this checkbox should be the rowid for the row which you want to delete. After checking the box click submit. After submitting the page, grab the list of posted variables and then execute a SQL query: DELETE FROM [table][tr][td] WHERE [ROWID] = $_POST['checkbox value'];

Or something like that :)

Scot
[img]http://C:\Documents and Settings\L340C27\My Documents\My Pictures\error.bitmap[/img]

<?php

  // connect and select the database
  $conn = mssql_connect($host, $user, $password) or die(mssql_error());
  $db = mssql_select_db($dbName, $conn) or die(mssql_error());

$sql="SELECT * FROM Job";
$result=mssql_query($sql);

$count=mssql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF">&nbsp;</td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mssql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>JobID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>JobTitle</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Location</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>CompanyName</strong></td>
</tr>
<?php
while($rows=mssql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" value="<?php echo $rows['JobID']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['JobID']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['JobTitle']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['Location']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['CompanyName']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input type="submit" name="delete" value="Delete"></td>
</tr>
<?php
//Check if delete button active, start this
if(isset($_POST['delete'])){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM Job WHERE JobID='$del_id'";
$result = mssql_query($sql);
}
if($result){
//echo "<meta http-equiv=\"refresh\" content=\"0;URL=DeleteJ.php\">";
}

}
mssql_close($conn);
?>
</table>
</form>
</td>
</tr>
</table>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.