Jump to content
php.lv forumi

mysql delete by id


autly

Recommended Posts

<?
//connect to mysql
//change user and password to your mySQL name and password
mysql_connect("localhost","root","");

//select which database you want to edit
mysql_select_db("aaa");

//If cmd has not been initialized
if(!isset($cmd))
{
  //display all the news
  $result = mysql_query("select * from news order by id");

  //run the while loop that grabs all the news scripts
  while($r=mysql_fetch_array($result))
  {
  //grab the title and the ID of the news
  $title=$r["title"];//take out the title
  $id=$r["id"];//take out the id

 //make the title a link
  echo "<a href='delete.php?cmd=delete&id=$id'>$title - Delete</a>";
  echo "<br>";
}
}
?>

<?
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM news WHERE id=$id";
$result = mysql_query($sql);
echo "Row deleted!";
}
?>

 

Ta vins jau strada, bet ir maza kluda kautkur paslepusies, neesmu es nekads profins php un mysql lietas, bet nu maacos kaa varu.

Kluda ir sekojoshna

es ataisu delete.php ar mozila firefox. Un tur errors, bet delete strada. Reku source cods kas nemts no firefox mozila's

 

<a href='delete.php?cmd=delete&id=14'>Patiesība par online atkarību - Delete</a><br><a href='delete.php?cmd=delete&id=15'>ASUS plate ar iebūvētu Skype - Delete</a><br><a href='delete.php?cmd=delete&id=16'>Konkurss — uzlauz mājas lapu un iegūsti «Playstation 3» - Delete</a><br>

<br />

<b>Notice</b>: Undefined index: cmd in <b>c:\program files\webserver\www\delete.php</b> on line <b>30</b><br />

 

Kas var paliidzeet?

Link to comment
Share on other sites

×
×
  • Create New...