Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá !
Sou novo no php estou tendo dificuldades para encontrar os erros no código abaixo.
Quando clicado nos botões alterar, excluir e inserir não tá realizando nenhuma ação que seria chamar o formulário , também estou com problema com as na declaração das variáveis $Inserir ,$Alterar, $Excluir e $acao (Notice: Undefined variable) só consigo roda o código sem erro nas variáveis colocando na frente o @.
este código esta conectando sem erro com o banco de dados.
quando clico sobre os botões me mostra na barra de endereço do navegador
botão alterar ?acao=Alterar&id=6
botão excluir me mostra ?Excluir=ok&id=6
botão inserir ?acao=Inserir
código que chama o formulário
<?php } else { ?>
<table width="99%" border="1" cellspancing="0" cellpadding="0" >
<tr>
<td width="91%">Categorias</td>
<td colspan="2" ><div align="center">Ação</div></td>
</tr>
<?php $sql = mysql_query("select * from categorias");
while ($coluna = mysql_fetch_array($sql)){ ?>
<tr>
<td><?php echo $coluna['categoria'] ?></td>
<td width="4%"><a href="?acao=Alterar&id=<?php echo $coluna['id_categoria']; ?>"><img src="img/editar.png" width="16" height="16" border="0" ></a></td>
<td width="5%"><a href="?Excluir=ok&id=<?php echo $coluna['id_categoria']; ?>"><img src="img/excluir.png" width="16" height="16" border="0" ></a></td>
</tr>
<?php } ?>
<tr>
<td colspan="3"><div align="right"><a href="?acao=Inserir"><img src="img/inserir.png" width="55" height="16" border="0" ></div></a></td>
</tr>
</table>
<?php }?>
<p> </p>
</div></td>
</tr>
</table></td></td>
</tr>
código do formulário
<form id="forml" name="forml" method="post" action="<?php echo $PHP_SELF ;?>" >
<table width="300" border="0" align="center" cellspacing="0" cellpadding="2"
border="1">
<tr>
<td width="93"><b>Categoria</b></td>
<td width="207"><label>
<input type="text" name="txt_categoria" id="txt_categoria" size="35" value="<?php echo @mysql_result($sql,0,categoria); ?>"/>
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="hidden" name="id" value="<?php echo $id ;?>" />
<input type="hidden" name="<?php echo $acao ?>" value="ok" />
<input name="Submit" type="submit" value="OK" />
<label>
<input type="text" name="textfild" value="<?php echo $id ;?>" />
</label>
<label>
<input type="text" name="ACAO" value="ok" />
</label>
</div>
</label> </td>
</tr>
</table>
</form>
Codigo categoria.php
<?php include "conexao.php";
if ($Inserir == "ok" ) {
mysql_query ("INSERT INTO (categorias) values ('$txt_categoria')");
}
if ($Alterar == "ok" ) {
mysql_query ("UPDATE categorias SET categoria='$txt_categoria' WHERE id_categoria = $id");
}
if ($Excluir == "ok"){
mysql_query ("DELETE FROM categorias WHERE id_categoria = $id");
}
?>
<!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>Categorias</title>
</head>
<body>
<table width="750" border="0" align="center" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2"><?php include "cabecalho.php";?></td>
</tr>
<tr>
<td width="172" valign="top"><?php include "menu.php";?></td>
<td width="578"><table width="100%" border="0" align="center">
<tr>
<td> </td>
</tr>
<tr>
<td><div align="center" class="stylel">
<p>Categoria</p>
<?php if($acao != ""){
$sql = mysql_query(" SELECT * FROM categorias Wehere id_categoria = $id");?>
<form id="forml" name="forml" method="post" action="<?php echo $PHP_SELF ;?>" >
<table width="300" border="0" align="center" cellspacing="0" cellpadding="2"
border="1">
<tr>
<td width="93"><b>Categoria</b></td>
<td width="207"><label>
<input type="text" name="txt_categoria" id="txt_categoria" size="35" value="<?php echo @mysql_result($sql,0,categoria); ?>"/>
</label></td>
</tr>
<tr>
<td colspan="2"><label>
<div align="center">
<input type="hidden" name="id" value="<?php echo $id ;?>" />
<input type="hidden" name="<?php echo $acao ?>" value="ok" />
<input name="Submit" type="submit" value="OK" />
<label>
<input type="text" name="textfild" value="<?php echo $id ;?>" />
</label>
<label>
<input type="text" name="ACAO" value="ok" />
</label>
</div>
</label> </td>
</tr>
</table>
</form>
<?php } else { ?>
<table width="99%" border="1" cellspancing="0" cellpadding="0" >
<tr>
<td width="91%">Categorias</td>
<td colspan="2" ><div align="center">Ação</div></td>
</tr>
<?php $sql = mysql_query("select * from categorias");
while ($coluna = mysql_fetch_array($sql)){ ?>
<tr>
<td><?php echo $coluna['categoria'] ?></td>
<td width="4%"><a href="?acao=Alterar&id=<?php echo $coluna['id_categoria']; ?>"><img src="img/editar.png" width="16" height="16" border="0" ></a></td>
<td width="5%"><a href="?Excluir=ok&id=<?php echo $coluna['id_categoria']; ?>"><img src="img/excluir.png" width="16" height="16" border="0" ></a></td>
</tr>
<?php } ?>
<tr>
<td colspan="3"><div align="right"><a href="?acao=Inserir"><img src="img/inserir.png" width="55" height="16" border="0" ></div></a></td>
</tr>
</table>
<?php }?>
<p> </p>
</div></td>
</tr>
</table></td></td>
</tr>
<tr>
<td colspan="2"><?php include "rodape.php";?></td>
</tr>
</table>
</body>
</html>Carregando comentários...