- 0
PHP Check Box delete Script
-
Recently Browsing 0 members
- No registered users viewing this page.
-
Similar Content
-
Unofficial script lets in-place upgrade between Windows 10 and 11 Home / Pro editions
By hellowalkman,
- microsoft
- windows 11
- (and 11 more)
- 6 replies
- 2 views
-
- 15 replies
- 3 views
-
This Windows 10 Setup Script lets you fine-tune around 150 functions for new installs 1 2
By Steven P.,
- microsoft
- windows 10
- (and 7 more)
- 27 replies
- 1,654 views
-
algorithm [NEWBIE] Project assignment question - Given an array of strings, output the total number (n) of characters in the list
By kukubau,
- 2 answers
- 4,530 views
-
- 0 replies
- 2,887 views
-
Question
mallenium115
I am trying to delete my articles with selected checkboxes but I am having a little issue. When I click the delete button nothing happens, I am not sure where to append the variable, can someone help?
<?php
//include database
require_once('db_config.php');
$tbl_name="articles"; // Table name
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
//Provide the user with the number of articles in the database
//space string
$counttxt = "There are";
echo $counttxt;
print_r($count); $print = print 'articles in this database';
echo $print;
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="900" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Select the articles you would like delete.</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>ID</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Title</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Content</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Frontpage</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['articleID']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['articleID']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['title']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['content']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['frontpage']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?
//set the delete variable
$delete = (isset($_POST['checkbox']));
//use isset to check if the variable has been set or not
if ($delete){
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
echo 'You are deleting this article';
print_r($result);
// Check if delete button active, start this
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
//print out the checkbox
}
// if successful redirect to delete_multiple.php
if($result){
echo 'You have deleted the article(s)';
//echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
}
}
//mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
articles_list.php
Link to comment
Share on other sites
13 answers to this question
Recommended Posts