Ir para conteúdo
Fórum Script Brasil
  • 0

Deletar dados


CaioKroh

Pergunta

Fiz o script de deletar mais não esta funcionando...

alguém me ajuda a arrumar.

Pagina para ver os arquivos inseridos na tabela: LER.php

<?php

include("Connections/conn.php");

mysql_select_db($database_conn, $conn);

$query_mostrar = "SELECT * FROM tbpedidos ORDER BY id ASC";

$mostrar = mysql_query($query_mostrar, $conn) or die(mysql_error());

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

<!--

.style2 {

font-size: 14px;

font-weight: normal;

}

-->

</style>

</head>

<body>

<div align="center">

<p>

<?php

while($row_mostrar = mysql_fetch_assoc($mostrar)){

echo '<table width="500" border="0" cellspacing="0" cellpadding="0">

<tr>

<th scope="row"><form id="formdeleta" name="formdeleta" method="post" action="deletar.php">

<table width="500" border="1" cellspacing="0" cellpadding="0">

<tr>

<th width="116" height="30" bgcolor="#EEEEEE" scope="row"><div align="left">NOME:</div></th>

<th colspan="2" bgcolor="#EEEEEE" scope="row"><div align="left" class="style2">'.$row_mostrar['nome'].'</div></th>

<th width=68" bgcolor="#EEEEEE" scope="row">

<div align="center">

<input type="checkbox" name="notica[]" value='.$row_mostrar['id].' />

</div></th>

</tr>

<tr>

<th height="30" bgcolor="#EEEEEE" scope="row"><div align="left">CIDADE:</div></th>

<th width="228" height="30" bgcolor="#EEEEEE" scope="row"><div align="left" class="style2">'.$row_mostrar['cidade'].'</div></th>

<th width=88" bgcolor="#EEEEEE" scope="row">ESTADO:</th>

<th height="30" bgcolor="#EEEEEE" class="style2" scope="row">'.$row_mostrar['estado].'</th>

</tr>

<tr>

<th height="30" bgcolor="#EEEEEE" scope="row"><div align="left">MENSAGEM:</div></th>

<th height="30" colspan="3" bgcolor="#EEEEEE" scope="row"><div align="left" class="style2">'.$row_mostrar['pedido'].'</div></th>

</tr>

<tr>

<th height=30" colspan="4" scope="row"></th>

</tr>

</table>

<p>

</p>

</form>

</th>

</tr>

</table>';

}

?>

</p>

<p>

<a href="<?php echo "deletar.php?deletar=$id"; ?>"><input type="submit" name="button" id="button" value="Deletar" /></a>

</p>

</div>

</body>

</html>

<?php

mysql_free_result($mostrar);

?>

Pagina de deletar: DELETAR.php

<?php

$id = $_GET['id];

include("Connections/conn.php");

mysql_select_db($database_conn, $conn);

mysql_query("DELETE FROM tbpedidos where id=$id");

?>

Link para o comentário
Compartilhar em outros sites

7 respostass a esta questão

Posts Recomendados

  • 0

Vamos lá:

1 - Você está criando N formulários, se você quer selecionar vários checkboxs para serem apagados na mesma ação, coloca a tag <form antes do while e fecha a mesma tag depois do while, ou seja

<form....

while(){

}

</form>

2 - Estude da diferença entre o método POST e o GET, pois no teu formulário você está passando:

method="post"

Mas na hora de resgatar:

$id = $_GET['id']; <- Se está vindo por POST é $_POST['nome do campo'] e não $_GET['nome do campo']

3 - O teu checkbox:

<input type=checkbox" name="notica[]" value='.$row_mostrar['id].' />

Você deu o nome de notica[] (para criar um array, ok), só que na hora de resgatar:

$id = $_GET['id'];

??? O nome é notica e não id...

4 - Com você vai criar um novo array com o notica[], então recomendo que você use foreach para resgatar tudo que vai vir, lembre-se que quando o form for enviado ficará

$_POST['notica']'[iNDICE']

Já postei isso algumas vezes aqui no fórum.

Link para o comentário
Compartilhar em outros sites

  • 0

Bom, tem como alguém arrumar pra mim ? (to começando no PHP)

Obs.: já coloquei o formulario fora do while e mudei tudo pra GET...

LER.php

<?php

include("Connections/conn.php");

mysql_select_db($database_conn, $conn);

$query_mostrar = "SELECT * FROM tbpedidos ORDER BY id ASC";

$mostrar = mysql_query($query_mostrar, $conn) or die(mysql_error());

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<style type="text/css">

<!--

.style2 {

font-size: 14px;

font-weight: normal;

}

-->

</style>

</head>

<body>

<div align="center">

<p>

<form id="formdeleta" name="formdeleta" method="get" action="deletar.php">

<?php

while($row_mostrar = mysql_fetch_assoc($mostrar)){

echo '<table width="500" border="0" cellspacing="0" cellpadding="0">

<tr>

<th scope="row">

<table width="500" border="1" cellspacing="0" cellpadding="0">

<tr>

<th width="116" height="30" bgcolor="#EEEEEE" scope="row"><div align="left">NOME:</div></th>

<th colspan="2" bgcolor="#EEEEEE" scope="row"><div align="left" class="style2">'.$row_mostrar['nome'].'</div></th>

<th width=68" bgcolor="#EEEEEE" scope="row">

<div align="center">

<input type="checkbox" name="notica[]" value='.$row_mostrar['id].' />

</div></th>

</tr>

<tr>

<th height="30" bgcolor="#EEEEEE" scope="row"><div align="left">CIDADE:</div></th>

<th width="228" height="30" bgcolor="#EEEEEE" scope="row"><div align="left" class="style2">'.$row_mostrar['cidade'].'</div></th>

<th width=88" bgcolor="#EEEEEE" scope="row">ESTADO:</th>

<th height="30" bgcolor="#EEEEEE" class="style2" scope="row">'.$row_mostrar['estado].'</th>

</tr>

<tr>

<th height="30" bgcolor="#EEEEEE" scope="row"><div align="left">MENSAGEM:</div></th>

<th height="30" colspan="3" bgcolor="#EEEEEE" scope="row"><div align="left" class="style2">'.$row_mostrar['pedido'].'</div></th>

</tr>

<tr>

<th height=30" colspan="4" scope="row"></th>

</tr>

</table>

<p>

</p>

</th>

</tr>

</table>';

}

?>

</p>

<p>

<a href="deletar.php"><input type="submit" name="button" id="button" value="Deletar" /></a></p>

</form>

</div>

</body>

</html>

<?php

mysql_free_result($mostrar);

?>

DELETAR.php

<?php

$id = $_GET['id];

include("Connections/conn.php");

mysql_select_db($database_conn, $conn);

mysql_query("DELETE FROM tbpedidos where id='$id'") or die (mysql_error());

?>

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,8k
×
×
  • Criar Novo...