Where

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
coyners25
Forum Newbie
Posts: 2
Joined: Tue Jul 24, 2007 9:43 am

Where

Post 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]
Last edited by coyners25 on Tue Jul 24, 2007 10:35 am, edited 1 time in total.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post 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;
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
coyners25
Forum Newbie
Posts: 2
Joined: Tue Jul 24, 2007 9:43 am

Post 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
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

I'm happy to help :)
Post Reply