Jump to content

Deleting a row with a link (MySQL)


rwachowiak

Recommended Posts

heres what i got so far:

 

when i click the delete link it wants to actually download the update.php

 

<?php include 'libs/dbopen.php';


//If cmd is not hit
if(!isset($cmd)) 
{	
	$query  = "SELECT * FROM news Order by DateAdded DESC";
	$result = mysql_query($query);
  
  
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
echo 	"<span class='titlebar3'><a href='update.php?cmd=delete&id={$row['id']}'>{$row['Title']} - Delete</a></span><br>" .
	"{$row['Content']} <br>" .
	"<span class='description'>Date Added: {$row['DateAdded']}</span> <br><br>";
	}		
}
?>




<?
if($cmd=="delete")
{
    $sql = "DELETE FROM news WHERE id={$row['id']}";
    $result = mysql_query($sql);
    echo "Row deleted!";
}
include 'libs/dbclose.php';
?>

Link to comment
Share on other sites

Just a shot here, since I assume you mean the update.php and not upload.php and assuming PHP is installed and works.

 

Try to change your <? tag to <?php

 

whoops yes, it is update.php

 

and yes php is installed and working fine, i have a few other scripts ive got going on this site

 

and i tried that <?php and no luck!

Link to comment
Share on other sites

<?php

if($_GET['cmd']=="delete")
{
    $sql = "DELETE FROM news WHERE id={$_GET['id']}";
    $result = mysql_query($sql) or die (mysql_error());
    echo "Row deleted!";
}
include 'libs/dbclose.php';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.