← Desenvolvimento

Apagar registos da base de dados

Lida 1835 vezes

Offline

Bruno Mota 
Membro
Mensagens 1733 Gostos 3
Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

eu estou a fazer um sistema para a empresa do meu pai com um backoffice mas o que se passa e que faço o codigo para apagar registos da base de dados e da erro alguem pode ver o que estou a fazer mal?
 
Código: [Seleccione]
<?
include 'mysql.php';
$sql = "SELECT * FROM noticias ORDER BY id";
$query = mysql_query($sql);
$linhas = mysql_num_rows($query);
if ($linhas == 0)
{
echo "Nenhum registro encontrado";
}
else{
while ($linha = mysql_fetch_array($query))
{
$id = $linha['id'];
$titulo = $linha['titulo'];
$imagem = $linha['imagem'];
$noticia = $linha['noticia'];
$autor = $linha['autor'];

echo "
<table border=\"0\" width=\"100%\" id=\"table1\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td colspan=\"2\" bgcolor=\"#C0C0C0\">$titulo</td>
</tr>
<tr>
<td width=\"14%\"><img src=\"$imagem\" width=\"150\" height=\"150\"></td>
<td width=\"86%\" valign=\"top\">$noticia</td>
</tr>
<tr>
<td colspan=\"2\" bgcolor=\"#C0C0C0\">
<p align=\"right\"><font size=\"2\">Por: $autor -|-<a href='?acao=apagar&id=$id'>EXCLUIR NOTICIA</a></font></td>
</tr>
</table><hr>";
}
}  

$id = $_GET['id'];
$acao = $_GET['acao'];
if ($acao == "apagar"){
$sql = "DELETE * FROM noticias WHERE id='$id'";
$query = mysql_query($sql) or die(mysql_error());
echo  "Excluido com sucesso";
}
?>


já corri o codigo vezes sem conta
Offline

kingless 
Membro
Mensagens 857 Gostos 0
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2 Level 1

Se mostrasses o erro que o código mostra ja ajudas-me a ajudar-te   :)
Offline

Bruno Mota 
Membro
Mensagens 1733 Gostos 3
Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM noticias WHERE id='3'' at line 1
Offline

kingless 
Membro
Mensagens 857 Gostos 0
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2 Level 1

Citação de: "mota77"
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM noticias WHERE id='3'' at line 1


Tem que ser:
DELETE FROM noticias WHERE id='3'

E não:
DELETE * FROM noticias WHERE id='3'
Offline

Bruno Mota 
Membro
Mensagens 1733 Gostos 3
Troféus totais: 28
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Level 5 Level 4 Level 3 Level 2 Level 1

que estupidez lol eu desde que ando a trabalhar que nem um cão nas montagens fiquei assim