checkbox problem
Posted: Wed Jul 29, 2009 10:04 am
Hallo im really new with the php code and have tried to delete via checkbox some mysql data
For some reason cannot do that.
Undefined variable checkbox and never deletes anything.
If somebody could point to me where i m wrong id appreciate it a lot.
<?php require_once ('inc/gymgeneralinfo.php'); ?>
<?php
if (!isset($_SESSION['9ocustomerlogin']) || $_SESSION['9ocustomerlogin']!=true){
die("Access denied...") ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $GLOBALS['site_title']?>-Διαγραφή Ανακοίνωσης</title>
<script>
$(document).ready(function(){
$("#chk_all").change(function(v,n){
var chk=this
$('input[name=\'anak[]\']').each(function(obj){
if(chk.checked==true)
this.checked=true
else
this.checked=false
});
});
});
</script>
</head>
<body bgcolor="<?php echo $GLOBALS['site_color'] ?>">
<?php require_once ('inc/gymlinks.php'); ?>
<form name="form1" method="post" action="9odiagrafianakoinosis.php">
<table id="table-menu2" width="68%" height="134" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="60" height="48" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<input name="all" type="checkbox" value="all" class="L" id="chk_all"/> all</td>
<td width="92" height="48" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<font class="L">Aριθμός</font></td>
<td width="194" height="48" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<font class="L">Δημοσιεύτηκε</font></td>
<td width="412" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<font class="L">Θέμα</font></td>
</tr>
<?php
$query = sprintf("SELECT * FROM anakoinoseis WHERE date != '' ORDER BY date DESC");
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}else if(mysql_num_rows($result)>0){
while($row= mysql_fetch_assoc($result)) {
$published=$row["DATE"];
$thema=$row["thema"];
$anakoinosi=$row["anakoinosi"];
$link1=$row["link1"];
$count=mysql_num_rows($result);
?>
<tr>
<td align="center" style=" color:#FFF; border-right:1px solid #FFF; border-bottom:1px solid #FFF"width="60">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['anakoinosi']; ?>" onclick="function(form1)"></td>
<td style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;border-top:0" align="center"><font class="K">
<?php echo $anakoinosi;?></font></td>
<td style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;border-top:0" align="center"><font class="K">
<?php echo $published; ?></font></td>
<td style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;border-top:0" align="center"><font class="K">
<?php echo $thema; ?><br /><?php echo $link1;?></font></td>
</tr>
<?php } ?>
<br />
<br />
<table width="11%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><font height="60" colspan="2" align="center">
<input name="delete" type="submit" id="delete" value="Delete">
</font></td>
</tr>
</table>
</form>
<?
if(isset($_POST['delete'])){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
if ($del_id==NULL){echo 'bla';}
$sql = "DELETE FROM anakoinoseis WHERE anakoinosi='$del_id'";
$result1 = mysql_query($sql);
/*if($result1){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=9odiagrafianakoinosis.php\">";
}*/
}//end for
}//endif
}else{
?>
<tr >
<td colspan="7">no record</td>
</tr>
</table>
<?php } ?>
</body>
</html>
For some reason cannot do that.
Undefined variable checkbox and never deletes anything.
If somebody could point to me where i m wrong id appreciate it a lot.
<?php require_once ('inc/gymgeneralinfo.php'); ?>
<?php
if (!isset($_SESSION['9ocustomerlogin']) || $_SESSION['9ocustomerlogin']!=true){
die("Access denied...") ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $GLOBALS['site_title']?>-Διαγραφή Ανακοίνωσης</title>
<script>
$(document).ready(function(){
$("#chk_all").change(function(v,n){
var chk=this
$('input[name=\'anak[]\']').each(function(obj){
if(chk.checked==true)
this.checked=true
else
this.checked=false
});
});
});
</script>
</head>
<body bgcolor="<?php echo $GLOBALS['site_color'] ?>">
<?php require_once ('inc/gymlinks.php'); ?>
<form name="form1" method="post" action="9odiagrafianakoinosis.php">
<table id="table-menu2" width="68%" height="134" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="60" height="48" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<input name="all" type="checkbox" value="all" class="L" id="chk_all"/> all</td>
<td width="92" height="48" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<font class="L">Aριθμός</font></td>
<td width="194" height="48" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<font class="L">Δημοσιεύτηκε</font></td>
<td width="412" align="center" style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;">
<font class="L">Θέμα</font></td>
</tr>
<?php
$query = sprintf("SELECT * FROM anakoinoseis WHERE date != '' ORDER BY date DESC");
$result = mysql_query($query);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}else if(mysql_num_rows($result)>0){
while($row= mysql_fetch_assoc($result)) {
$published=$row["DATE"];
$thema=$row["thema"];
$anakoinosi=$row["anakoinosi"];
$link1=$row["link1"];
$count=mysql_num_rows($result);
?>
<tr>
<td align="center" style=" color:#FFF; border-right:1px solid #FFF; border-bottom:1px solid #FFF"width="60">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['anakoinosi']; ?>" onclick="function(form1)"></td>
<td style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;border-top:0" align="center"><font class="K">
<?php echo $anakoinosi;?></font></td>
<td style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;border-top:0" align="center"><font class="K">
<?php echo $published; ?></font></td>
<td style=" border:1px solid <?php echo $GLOBALS['site_letterscolor1'] ?>;border-top:0" align="center"><font class="K">
<?php echo $thema; ?><br /><?php echo $link1;?></font></td>
</tr>
<?php } ?>
<br />
<br />
<table width="11%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><font height="60" colspan="2" align="center">
<input name="delete" type="submit" id="delete" value="Delete">
</font></td>
</tr>
</table>
</form>
<?
if(isset($_POST['delete'])){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
if ($del_id==NULL){echo 'bla';}
$sql = "DELETE FROM anakoinoseis WHERE anakoinosi='$del_id'";
$result1 = mysql_query($sql);
/*if($result1){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=9odiagrafianakoinosis.php\">";
}*/
}//end for
}//endif
}else{
?>
<tr >
<td colspan="7">no record</td>
</tr>
</table>
<?php } ?>
</body>
</html>