Jump to content

Delete Query - please help?


Mr Chris

Recommended Posts

Hi All,

 

Here’s what I’m trying to do:

 

- Output the last 60 results in my db - works

- Delete a record – does not work

 

Can anyone see why my delete query won’t work?

 

It seems to have two problems:

 

1) It does not delete a record

2) The header re-direct says can’t modify header information

 

Thanks

 

Chris

 


<FORM NAME="form1" METHOD="post" ACTION="">
<?php 

$sql = "SELECT *, DATE_FORMAT(published_web_date, '%d-%m-%Y') as formatted_date FROM cms_stories ORDER BY story_id DESC LIMIT 0,60"; 
$res = mysql_query($sql) or die(mysql_error());

$n = 0;
$total_results = mysql_num_rows($res); 

// delete query starts here 
if(isset($_POST['Submit']))
{
$total = $_POST['total'];
$td = 0;
$i = 0;

for($i = 1; $i <= $total; $i++)
{
if(isset($_POST["d$i"]))
{
mysql_query("DELETE FROM cms_stories WHERE story_id=".$_POST["d$i"],$link);
$td++;
}
}
header("Location: edit_list.php"); 
}
// delete query ends here 


if($total_results > 0) 
        { 
            echo "<b><font color='#0066CC'>>></font></b> Here are the <strong>".$total_results."</strong> most recent stories added to the database <br /><br />Here are those results, listed in ascendng order. <br /><br />"; 
        
echo "<table width='100%' border='0' cellpadding='1' cellspacing='1' bgcolor='#666666'>"; 
echo "<tr>";  
echo "<td height='20' colspan='6' bgcolor='#0066CC'><font color='#FFFFFF'><strong><span class='story_listing'>:: Please the latest stories added to the site below...</span></strong></font></td>"; 
echo "</tr>"; 
echo "<tr bgcolor='#FFFFCC'>"; 
echo "<td width='10%'><strong><font color='#666666'><div align='center'><span class='story_listing'>#</span></strong></div></font></td>";
echo "<td width='10%'><strong><font color='#666666'><div align='center'><span class='story_listing'>Publish Date</span></strong></div></font></td>";
echo "<td width='55%'><strong><font color='#666666'><span class='story_listing'>Headline</span></strong></font></td>";
echo "<td width='10%'><strong><font color='#666666'><div align='center'><span class='story_listing'>Picture</span></strong></div></font></td>";
echo "<td width='10%'><strong><font color='#666666'><div align='center'><span class='story_listing'>Video</span></strong></div></font></td>";
echo "<td width='10%'><strong><font color='#666666'><div align='center'><span class='story_listing'>Sound</span></strong></div></font></td>";
echo "</tr>";

	}

$res = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_object($res)) { 

echo "<tr>"; 
echo "<td width='10%' bgcolor='#EEEEEE'><input type='checkbox' name='d$n' value='". $row->story_id."'></td>";
echo "<td width='10%' bgcolor='#EEEEEE'><span class='story_listing'><div align='center'>$row->formatted_date</div></span></td>";
echo "<td width='55%' bgcolor='#FFFFFF'><span class='story_listing'><a href='../stories/edit.php?story_id=". $row->story_id."'>". stripslashes($row->headline) ."</a></span></td>";
echo "<td width='10%' bgcolor='#FFFFFF'><span class='story_listing'><a href='../stories/edit_picture.php?story_id=". $row->story_id."'><img src='../../images/add-image.png' width='80' height='15' class='no_border'></a></span></td>";
echo "<td width='10%' bgcolor='#FFFFFF'><span class='story_listing'><a href='../stories/edit_video.php?story_id=". $row->story_id."'><img src='../../images/add-video.png' width='80' height='15' class='no_border'></a></span></td>";
echo "<td width='10%' bgcolor='#FFFFFF'><span class='story_listing'><a href='../stories/edit_sound.php?story_id=". $row->story_id."'><img src='../../images/add-sound.png' width='80' height='15' class='no_border'></a></span></td>";
echo "</tr>";
} 

echo "</table>";                                    

?>
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit" CLASS="button"> 
<INPUT NAME="total" TYPE="hidden" ID="total" VALUE="<?php echo $n?>"> 
</form>

Link to comment
https://forums.phpfreaks.com/topic/40858-delete-query-please-help/
Share on other sites

Your delete query should not be in between form tags. Move them down to where you start your form. You cannot sent any output to the browser before a header. I am not sure if the form tag is an output or not since it does not print anything out to the screen but in any case you should move it.

 

echo '<FORM NAME="form1" METHOD="post" ACTION="">';
if($total_results > 0) 
        {
// rest of code

 

Ray

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.