0
I want to give delete in a student for that I want to delete the records of that same student of all the tables where he is and his image of the folder where it is was saved for that I use the following code :
<?php
/*
* Verifica se a variável com o id do aluno está definida
* Se não estiver volta à página inicial
*/
if (!isset ($_GET['idc']))
print "<meta HTTP-EQUIV='Refresh' CONTENT='0;URL=menuadmin.php?id=4'>";
// Pega no registo selecionado para saber o nome
// da imagem ($al_img) para depois a eliminar
$sql = "SELECT * FROM Aluno WHERE al_id = ".$_GET['idc'];
$result = mysql_query($sql);
if (mysql_num_rows($result)!= 0){
$registo = mysql_fetch_assoc($result);
extract($registo);
//Elimina a imagem
unlink("imagens/aluno/".$al_img);
}
/* Elimina o registo */
mysql_query("DELETE FROM Inscricao,
Aluno,
EncarregadoDeEducacao,
Musica_Aluno,
OutrasAtividades_Aluno,
Explicacoes_Aluno,
Psicologia_Aluno,
SalaDeEstudo_Aluno
WHERE
Inscricao.al_id = Aluno.al_id AND
EncarregadoDeEducacao.ee_id = Inscricao.ee_id AND
Musica_Aluno.al_id = Inscricao.al_id AND
OutrasAtividades_Aluno.al_id = Inscricao.al_id AND
Explicacoes_Aluno.al_id = Inscricao.al_id AND
Psicologia_Aluno.al_id = Inscricao.al_id AND
SalaDeEstudo_Aluno.al_id = Inscricao.al_id AND
Inscricao.al_id = ".$_GET['idc'])
echo mysql_error();
/* Verifica se deu erro ao eliminar o registo */
if (mysql_error()){
echo "<script type='text/javascript'>";
echo 'alert ("Erro ao eliminar ao aluno...");';
echo "</script>";
}
/* Volta à página inicial */
print "<meta HTTP-EQUIV='Refresh' CONTENT='0;URL=menuadmin.php?id=4'>";
?>
The mistake you give me is this: :
Parse error: syntax error, Unexpected T_ECHO in C: xampp htdocs estagio eliminaraluno.php on line 32
What’s wrong with the code?
--------EDITED : ------
I’ve already put the ;
now give me this mistake :
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 'WHERE Inscricao.al_id = Aluno.al_id AND Encarregad' at line 1
Possibly it’s because of the lack of
;
after the methodmysql_query()
.– Paulo Rodrigues
it is very likely that it is the missing point and comma at the end of the function mysql_query();
– Sam
take a look at the mysql ON DELETE CASCADE command could be very useful in this situation
– Sam
I’ve already put the
;
now give me this error : 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 'WHERE Registration.al_id = Student.al_id AND Guardian' at line 1– helder
Put ON DELETE CASCADE on fK’s
– Marcio.Rezende
http://stackoverflow.com/a/734610/1817673
– Jorge B.