Page 1 of 1

Where

Posted: Tue Jul 24, 2007 9:49 am
by coyners25
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello All,
I am trying to delete multiple records in PHP.
It displays the list of recordfs ok but when i click delete it will not delete anything.
Can anyone help before this drives me up the wall and around the bend!!

Cheers

Code: Select all

<?php require_once('../Connections/classified.php'); ?> 
<?php 
$maxRows_deleteticked = 50; 
$pageNum_deleteticked = 0; 
if (isset($_GET['pageNum_deleteticked'])) { 
  $pageNum_deleteticked = $_GET['pageNum_deleteticked']; 
} 
$startRow_deleteticked = $pageNum_deleteticked * $maxRows_deleteticked; 

mysql_select_db($database_classified, $classified); 
$query_deleteticked = "SELECT ID, Title, Description, `date`, image FROM classifieds"; 
$query_limit_deleteticked = sprintf("%s LIMIT %d, %d", $query_deleteticked, $startRow_deleteticked, $maxRows_deleteticked); 
$deleteticked = mysql_query($query_limit_deleteticked, $classified) or die(mysql_error()); 
$row_deleteticked = mysql_fetch_assoc($deleteticked); 

if (isset($_GET['totalRows_deleteticked'])) { 
  $totalRows_deleteticked = $_GET['totalRows_deleteticked']; 
} else { 
  $all_deleteticked = mysql_query($query_deleteticked); 
  $totalRows_deleteticked = mysql_num_rows($all_deleteticked); 
} 
$totalPages_deleteticked = ceil($totalRows_deleteticked/$maxRows_deleteticked)-1; 

?> 
<table width="400" border="0" cellspacing="1" cellpadding="0"> 
<tr> 
<td><form name="form1" method="post" action="<?php echo $PHP_SELF?>"> 
<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 mysql</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>Tile</strong></td> 
<td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> 
<td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> 
</tr> 

<?php do { ?> 
<tr> 
  <td align="center" bgcolor="#FFFFFF"><input type="Checkbox" name="deleterecord[]" value="<?php echo $row_deleteticked['ID']; ?>"></td> 
  <td bgcolor="#FFFFFF"><?php echo $row_deleteticked['ID']; ?><?php echo $row['ID']; ?></td> 
  <td bgcolor="#FFFFFF"><?php echo $row['Title']; ?></td> 
  <td bgcolor="#FFFFFF"></td> 
  <td bgcolor="#FFFFFF"></td> 
</tr> 
<?php } while ($row_deleteticked = mysql_fetch_assoc($deleteticked)); ?> 

<tr> 
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="delete"></td> 
</tr> 
//<?php 
// Check if delete button active, start this 

$sql="SELECT * FROM $classifieds"; 
$result=mysql_query($sql); 

$count=mysql_num_rows($result); 
$delete = $_POST['delete']; 

if ($delete){ 
for($i=0;$i<$count;$i++){ 
$del_id = $_POST["deleterecord[$i]"]; 
echo $del_id; 
$sql1 = "DELETE FROM $classifieds WHERE ID='$del_id'"; 
$result1 = mysql_query($sql1); 
} 

// if successful redirect to delete_multiple.php 
if($result1){ 
echo "<meta http-equiv="refresh" content="0;URL=delete.php">"; 
} 
} 
mysql_close(); 
?> 


</table> 
</form> 
</td> 
</tr> 
</table> 
<?php 
mysql_free_result($deleteticked); 
?>
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Jul 24, 2007 10:21 am
by miro_igov
WTH is this $_POST["deleterecord[$i]"]; ?

This may clarify the work with checkbox arrays.

Code: Select all

foreach($_POST['deleterecord'] as $key=>$del_id) echo $del_id;

Posted: Tue Jul 24, 2007 10:21 am
by superdezign
What sort of debugging have you tried so far? The error is likely either in your query or your handling of the POST variables. Isolate them (check if you can perform the query without the form, and check if you can get the form to do other things like echo "it's working") and figure out which one is the problem.

Posted: Tue Jul 24, 2007 11:41 am
by coyners25
miro_igov wrote:WTH is this $_POST["deleterecord[$i]"]; ?

This may clarify the work with checkbox arrays.

Code: Select all

foreach($_POST['deleterecord'] as $key=>$del_id) echo $del_id;
cheers
worked it out from that

Posted: Tue Jul 24, 2007 1:12 pm
by miro_igov
I'm happy to help :)