Author Topic: DELETE  (Read 341 times)

0 Members and 1 Guest are viewing this topic.

Offline -=[Vyorel]=-

  • Owner
  • Administrator
  • High-Roller
  • *
  • Posts: 4657
  • Respect: +176/-28
  • Gender: Male
  • Last Login:Yesterday at 12:06:56 AM
  • www.RO-PH.com
    • RO Power Hosting
  • Oras: Braila
DELETE
« on: November 23, 2009, 11:54:49 AM »
Stergerea poate fi facuta folosind id-ul inregistrarii dorite cu sintaxa:
Code: [Select]
DELETE FROM nume_tabel WHERE id='$id'; Primul fisier va contine un formular prin care introducem datele care vor fi cautate in baza de date.
Code: [Select]
/* urmeaza fisierul stergere.html */ <html>
<head><title>Stergere inregistrari</title>
</head>
<body>
<b>Cautare inregistrari in vederea stergerii</b>
<p>
<form method="POST" action="delete.php">
Numele cautat: <input type="text" name="nume"><br>
<input type="submit" value="Trimite">
</form>
</body>
</html>
Al doilea fisier va afisa rezultatul cautarii si un formular in care vom completa id-ul inregistrarii care dorim s-o stergem.
Code: [Select]
/* urmeaza fisierul delete.php */
<?php
include "conexiune.php";
$nume=$_POST['nume'];
$sql=mysql_query("SELECT * FROM proba WHERE nume LIKE '%$nume%'");
echo 
"<table border=\"1\">";
echo 
"<tr><td>ID</td><td>Nume</td><td>Prenume</td></tr>";
while (
$row=mysql_fetch_row($sql)) {
echo 
"<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>";
}
echo 
"</table>";
mysql_close($conexiune);
?>

<p>
<form method="POST" action="delete1.php">
ID-ul inregistrarii ce va fi stearsa: <input type="text" name="id" size="3"><br>
<input type="submit" value="Trimite">
</form>
Al treilea fisier preia id-ul dorit si sterge respective inregistrare.
Code: [Select]
/* urmeaza fisierul delete1.php */
<?php
include "conexiune.php";
$id=$_POST['id'];
$sql=mysql_query("DELETE FROM proba WHERE id='$id'");
if (!
$sql) {
die(
mysql_error());
} else {
echo 
"datele au fost sterse";
}
mysql_close($conexiune);
?>