
Ao Clicar, Deleta
#1
Posted 21/10/2004, 15:55
Achei isso e tenho uma dúvida...
PHP |
<html> <body> <?php include("config.php"); if ($id) { $resultado = mysql_query("SELECT * FROM shows WHERE id=$id",$link); $linha = mysql_fetch_array($resultado); printf("Data: %s\n<br>", $linha["data"]); printf("Horário: %s\n<br>", $linha["horario"]); printf("Local: %s\n<br>", $linha["local"]); printf("Descrição: %s\n<br>", $linha["descricao"]); } else { $resultado = mysql_query("SELECT * FROM shows",$link); if ($linha = mysql_fetch_array($resultado)) { do { printf("<a href=\"%s?id=%s\">%s %s</a><br>\n", $PHP_SELF, $linha["id"], $linha["local"], $linha["descricao"]); } while ($linha = mysql_fetch_array($resultado)); } else { echo "Nenhum registro encontrado!"; } } ?> </body> </html> |
Tem como quando eu clicar sobre o resultado ele apagar o registro do Banco de Dados?
Otavio Boari
#2
Posted 21/10/2004, 16:19
<?
mysql_query("DELETE FROM tabela WHRE id='$_GET[id]'");
E no link põe para deleta.php?id=x.

#3
Posted 21/10/2004, 17:24
Grande, teria que ficar assim:deleta.php
<?
mysql_query("DELETE FROM tabela WHRE id='$_GET[id]'");
E no link põe para deleta.php?id=x.![]()
PHP |
<html> <body> <?php //PEGA OS DADOS DA CONEXÃO COM O BD include("config.php"); // mostrar os dados de um registro (caso id exista) if ($id) { $resultado = mysql_query("SELECT * FROM shows WHERE id=$id",$link); $linha = mysql_fetch_array($resultado); printf("Nome: %s\n<br>", $linha["data"]); printf("Sobrenome: %s\n<br>", $linha["horario"]); printf("Endereço: %s\n<br>", $linha["local"]); printf("Posição: %s\n<br>", $linha["descricao"]); } else { // mostrar lista de employees $resultado = mysql_query("SELECT * FROM shows",$link); if ($linha = mysql_fetch_array($resultado)) { // mostrar lista se há registros do { printf("<a href=deleta.php%s?id=%s>%s %s</a><br>\n", $PHP_SELF, $linha["id"], $linha["local"], $linha["descricao"]); } while ($linha = mysql_fetch_array($resultado)); } else { // nenhum registro à ser mostrado echo "Nenhum registro encontrado!"; } } ?> </body> </html> |
Se sim me aparece o seguinte erro:
Warning: mysql_query(): Acesso negado para o usuário 'ODBC@localhost' (senha usada: NÃO) in c:\arquivos de programas\easyphp1-7\www\conexao\novo\deleta.php on line 2
Warning: mysql_query(): A link to the server could not be established in c:\arquivos de programas\easyphp1-7\www\conexao\novo\deleta.php on line 2
Vi lá no deleta.php que tinha algumas coisas que faltaram...mas deveria ficar assim né?
deleta.php
PHP |
<? mysql_query("DELETE FROM shows WHERE id='$_GET[id]'"); ?> |
Pois é, sabe o que aconteceu?
Otavio Boari
EDITANDO..............
Ow, foi mal... vi aqui que no arquivo deleta.php eu teria que colocar o include da conexão outra vez ficando assim:
deleta.php
PHP |
<? include("config.php"); mysql_query("DELETE FROM shows WHERE id='$_GET[id]'",$link); ?> |
Valeu pessoal....
Otavio Boari
Edição feita por: boari, 21/10/2004, 17:30.
#4
Posted 21/10/2004, 19:22
#5
Posted 22/10/2004, 11:27
É que antes tava:
PHP |
<? mysql_query("DELETE FROM shows WHERE id='$_GET[id]'"); ?> |
e não funfa...só depois de colocar assim:
PHP |
<? include("config.php"); mysql_query("DELETE FROM shows WHERE id='$_GET[id]'",$link); ?> |
è que funcionou...parece que necessitava mesmo de colocar o include com a conexão...nem sei se tem outra forma de fazer isso mas assim deu certinho aqui....
Vlws
Otavio boari
Edição feita por: boari, 22/10/2004, 11:28.
#6
Posted 22/10/2004, 16:37
Criei um arquivo (admin.php) com link pra "deletar" e outro pra "mudar".
A parte deletar é pelo arquivo deleta.php que tá aqui e funcionando direitinho agora vem a de modificar os dados...
Fiz o seguinte:
_muda.php
PHP |
<html> <body> <? include("config.php"); $resultado = mysql_query("SELECT * FROM shows WHERE id='$_GET[id]'",$link); $linha = mysql_fetch_array($resultado); ?> <table width=100% cellpading=0 cellspacing=0> <form name="form1" method="post" action="_mudou.php"><tr> <td><input type="text" value="<? echo $linha["local"]; ?>" name="textfield"></td> <td><input type="text" value="<? echo $linha["data"]; ?>" name="textfield"></td> <td><input type="text" value="<? echo $linha["horario"]; ?>" name="textfield"></td> <td><input type="text" value="<? echo $linha["descricao"]; ?>" name="textfield"></td> <td><input type="submit" name="submit" value=" Modificar >>> "></td> </tr></form> </table> </body> </html> |
e o _mudou.php
PHP |
<? include("config.php"); // conexao ?> <? $muda = mysql_query("UPDATE shows SET data='".$_POST['data']."' WHERE id='$_GET[id]'",$link); echo ($muda==true) ? "Modificado!" : "Erro ao modificar!"; ?> |
eu clico sobre "mudar" e ele vai pro form do _muda.php com os dados do id correpondente, troco alguma coisa, mando modificar e ele diz que ocorreu tudo ok mas quando eu vou olhar no banco de dados nada alterado...
Sabe o que pode tá contecendo?
Otavio Boari
Edição feita por: boari, 22/10/2004, 16:41.
#7
Posted 22/10/2004, 16:48
<form name="form1" method="post" action="_mudou.php?id=<?=$_GET[id]?>"><tr>
#8
Posted 22/10/2004, 17:24
Alterou sim mas aconteceu o seguinte:
Mudei a informação do campo "local" somente e ele inseriu no lugar certo mas deletou as informações que tavam na "data" e deixou o resto como estava
Não sei se tá certo mas coloquei agora o _mudou.php assim:
PHP |
<? include("config.php"); // conexao ?> <? $muda = mysql_query("UPDATE shows SET data='".$_POST['data']."',local='".$_POST['local']."',descricao='".$_POST['descricao']."',horario='".$_POST['horario']."' WHERE id='$_GET[id]'",$link); echo ($muda==true) ? "Modificado!" : "Erro ao modificar!"; ?> |
daí eu troco qualquer info agora e ele deleta todas as infos dos campos do id que eu cliquei....
Otavio boari
#9
Posted 22/10/2004, 19:52
#10
Posted 25/10/2004, 14:40
desculpe a demora...Quê??? Ele está apagando o registro???
exatamente... ele deleta as informações deixando somente o ID correspondente e os campos em branco...
Otavio boari
#11
Posted 25/10/2004, 17:05
#12
Posted 25/10/2004, 17:08
a tabela tem os campos:
id | data | local | descricao | horario
Otavio Boari
#13
Posted 25/10/2004, 20:07
#14
Posted 26/10/2004, 14:23
_muda.php
<html> <body> <? include("config.php"); $resultado = mysql_query("SELECT * FROM shows WHERE id='$_GET[id]'",$link); $linha = mysql_fetch_array($resultado); ?> <table width=100% cellpading=0 cellspacing=0> <form name="form1" method="post" action="_mudou.php?id=<?=$_GET[id]?>"><tr> <td><input type="text" value="<? echo $linha["local"]; ?>" name="textfield"></td> <td><input type="text" value="<? echo $linha["data"]; ?>" name="textfield"></td> <td><input type="text" value="<? echo $linha["horario"]; ?>" name="textfield"></td> <td><input type="text" value="<? echo $linha["descricao"]; ?>" name="textfield"></td> <td><input type="submit" name="submit" value=" Modificar >>> "></td> </tr></form> </table> </body> </html>
que remete pro
_mudou.php
PHP |
<? include("config.php"); // conexao ?> <? $muda = mysql_query("UPDATE shows SET data='".$_POST['data']."',local='".$_POST['local']."',descricao='".$_POST['descricao']."',horario='".$_POST['horario']."' WHERE id='$_GET[id]'",$link); echo ($muda==true) ? "Modificado!" : "Erro ao modificar!"; ?> |
não me parece ter nada errado...
Otavio Boari
Edição feita por: boari, 26/10/2004, 14:25.
#15
Posted 26/10/2004, 15:33
_muda.php
PHP |
<html> <body> <? include("config.php"); $resultado = mysql_query("SELECT * FROM shows WHERE id='$_GET[id]'",$link); $linha = mysql_fetch_array($resultado); ?> <table width=100% cellpading=0 cellspacing=0> <form name="form1" method="post" action="_mudou.php?id=<?=$_GET[id]?>"><tr> <td><input type="text" value=<? echo $linha["local"]; ?> name="textfield"></td> <td><input type="text" value=<? echo $linha["data"]; ?> name="textfield"></td> <td><input type="text" value=<? echo $linha["horario"]; ?> name="textfield"></td> <td><input type="text" value=<? echo $linha["descricao"]; ?> name="textfield"></td> <td><input type="submit" name="submit" value=" Modificar >>> "></td> </tr></form> </table> </body> </html> |
Os <? e ?> dentro de " " naum vão funcionar não! Tenta o seguinte
PHP |
<?php $NickName = 'Atentado'; $ICQ = '339591460'; $MSN = 'pauloimmig@msn.com ?> |
1 user(s) are reading this topic
0 membro(s), 1 visitante(s) e 0 membros anônimo(s)