Jump to content


Photo

newbie Q: Need to make and display link + page in Database


  • Please log in to reply
24 replies to this topic

#21 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 14 July 2006 - 04:41 PM

My input and output code works perfect... But now the DELETE code :

<? 
include('dbconnect.php');

if(!isset($cmd)) 
{

   $result = mysql_query("select * from yourtable") or die(mysql_error());
   

   while($r=mysql_fetch_array($result)) 
   { 

      $title=$r["titlefield"];
      $id=$r["idfield"];
     
	
      echo "<a href='treatedit.php?cmd=delete&idfield=$id'>$title - Delete</a>";
      echo "<br>";
    }
}
?>
<?
if($cmd=="delete")
{
    $sql = "DELETE FROM yourtable WHERE idfield='$id'";
    $result = mysql_query($sql) or die(mysql_error());
    echo "treat deleted";
}
?>

It displays the correct links and gives the correct output (treat deleted). But it does not actually delete :-s

Can U help once again :-)

Thanks in advance

#22 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 15 July 2006 - 09:23 AM

Can anyone help me out?

I think there is a problem with the idfield & $id but I cant see it...

Thanks in advance

#23 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 July 2006 - 09:32 AM

Where is it getting the $id from? Was this supposed to come from a url? If so you will probably need to do:
$id = $_GET['id']

#24 t.bo

t.bo
  • Members
  • PipPipPip
  • Advanced Member
  • 57 posts

Posted 15 July 2006 - 09:54 AM

Ok thanks again...
Should this piece of code be put in the beginning of the code or already in the delete section?

grtz

#25 GingerRobot

GingerRobot
  • Staff Alumni
  • Advanced Member
  • 4,086 posts
  • LocationUK

Posted 15 July 2006 - 09:58 AM

you might as well place it at the top of your file.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users