come faccio a passare l'id di un record selezionato dall'utente dopo aver eseguito la select di ricerca...al fine di eliminarlo?
cerca.php
Codice PHP:
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Impossibile connettersi: ' . mysql_error());
}
mysql_select_db("libri", $con);
$prezzo = $_POST['prezzo'];
$due = $_POST['due'];
$testo = $_POST['testo'];
if ( $testo == '' ) {
$result = mysql_query("SELECT * FROM libri WHERE $prezzo");
} else {
$result = mysql_query("SELECT * FROM libri WHERE $due LIKE '%$testo%'");
}
while($row = mysql_fetch_array($result))
{
$titolo = $row['titolo'];
$autore = $row['autore'];
$immagine = $row['immagine'];
$pagine = $row['pagine'];
$editore = $row['editore'];
$anno = $row['anno'];
//HTML
echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
echo ('<html xmlns="http://www.w3.org/1999/xhtml">');
echo ('<head>');
echo ('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />');
echo ('<title>Documento senza titolo</title>');
echo ('<link href="CSS/style.css" rel="stylesheet" type="text/css" />');
echo ('</head>');
echo('<body>');
// TABELLA
echo ('<table width="200" border="0" cellspacing="0" cellpadding="0">');
echo ('<tr>');
echo ('<td><table width="422" border="0" cellspacing="0" cellpadding="0">');
echo ( '<tr>');
echo ('<td width="50" valign="top">[img]upload/'. $immagine . '[/img]</td>');
echo ('<td width="572" valign="top"><table width="312" border="0" cellspacing="0" cellpadding="0">');
echo ('<tr>');
echo ('<td width="10"></td>');
echo ('<td width="302">[url="www.google.it"]' . $titolo .'[/url]</td>');
echo ('</tr>');
echo ('<tr>');
echo ('<td></td>');
echo ('<td class="titoloCopia2">' . $autore . " | ". $pagine . " Pagine" . " | ". $editore . " | ". $anno .'</td>');
echo ('</tr>');
echo ('<tr>');
echo ( '<td></td>');
echo ('<td><p class="menu">[url="www.google.it"]Modifica[/url] <span class="titoloCopia">|</span> [url="deleterecord.php?id=$id"]Elimina[/url]</p></td>');
echo ('</tr>');
echo ('<tr>');
echo ( '<td></td>');
echo ( '<td></td>');
echo ( '</tr>');
echo ('</table></td>');
echo ('</tr>');
echo ('</table></td>');
echo ('</body>');
// FINE HTML
echo ('</html>');
echo ('
');
}
mysql_close($con);
?>
deleterecord.php
Codice PHP:
<?php
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Impossibile connettersi: ' . mysql_error());
}
mysql_select_db("libri", $con);
$elimina = @mysql_query ("DELETE from libri WHERE id = $_POST['id']");
if ($elimina) {
echo ('Il record è stato eliminato!');
} else {
echo ('errore: impossibile eliminare il record!');
}
grazie!