Estou fazendo um sistema de cadastro com edição e exclusão, mas estou tendo um pequeno problema na parte do UPDATE...
Quando eu chamo o registro para alteração funciona normalmente. Mas quando eu vou realizar a alteração ele simplesmente não grava no banco.
Se puderem me ajudar ficarei muito grato, mas gostaria que me explicassem o meu erro pois sou iniciante.
Segues os códigos.
listacadastroprof1.php
<html> <body> <table width="100%" border="0" cellspacing="0"> <tr> <td width="142" height="29"><div align="center"><strong><font size="1" face="verdana">Matricula Professor:</font></strong></div></td> <td width="451"><div align="center"><strong><font size="1" face="verdana">Nome:</font></strong></div></td> <td width="274"><div align="center"><strong><font size="1" face="verdana">Telefone:</font></strong></div></td> <td width="77"><div align="center"><strong><font size="1" face="verdana">Excluir:</font></strong></div></td> </tr> <tr> <td height="13" colspan="4"><hr color="#002D02" noshade align="left" width="950" size="1"></td> </tr> </table> <p> <? include"config.php"; $y = mysql_query("SELECT * FROM cadastro"); while($x = mysql_fetch_array($y)){ $matricula = $x[matricula]; $nome = $x[nome]; $telefone = $x[telefone]; echo' </p> <table width="100%" border="0" cellspacing="0"> <tr> <td width="144" height="33"><div align="center">'.$matricula.'<strong><font size="1" face="verdana"></font></strong></div></td> <td width="451"><div align="center">'.$nome.'</div></td> <td width="277"><div align="center">'.$telefone.'</div></td> <td width="72"><div align="center"> <a href="alteracadastro.php?matricula='.$matricula.'"> <img src="dadosmc.gif" alt="Altera Registro" width="32" height="32" border="0"></a> </div></td> </tr> <tr> <td height="13" colspan="4"><hr color="#002D02" noshade align="left" width="950" size="1"></td> </tr> </table> '; } ?> <p> </body> </html>
alteracadastro.php
<html> <body> <? include"config.php"; $matricula = $_GET['matricula']; //peguei o valor do campo que contem o name matricula echo'matricula='.$matricula.'<br>'; $y = mysql_query("SELECT * FROM cadastro WHERE matricula='$matricula'"); while($x = mysql_fetch_array($y)){ $matricula = $x[matricula]; $nome = $x[nome]; $telefone = $x[telefone]; ; } ?> <form name="form1" method="post" action="testecodigo.php?matricula='$matricula'"> <table width="100%" border="1"> <tr> <td><div align="center">Matricula</div></td> <td><div align="center">Nome</div></td> <td><div align="center">Telefone</div></td> <td><div align="center">Atualiza</div></td> </tr> <tr> <td><div align="center"><? echo''.$matricula.''?></div></td> <td><div align="center"> <input name="nome2" type="text" id="nome2" value="<? echo''.$nome.''?>" size="50"> </div></td> <td><div align="center"> <input name="telefone2" type="text" id="telefone2" value="<? echo''.$telefone.''?>" size="15"> </div></td> <td><div align="center"> <? { echo' <a href="testecodigo.php?matricula='.$matricula.'"> <img src="dadosmc.gif" alt="Altera Registro" width="32" height="32" border="0"></a> '; }?> </div></td> </tr> </table> </form> </body> </html>
testecodigo.php
<html> <body> <? include"config.php"; // incluimos o arquivo de conexao com o db que nois criamos no passo 2 $matricula = $_GET["matricula"]; $telefone = $_POST["telefone"]; echo'matricula='.$matricula.'<br>'; $x = mysql_query("UPDATE cadastro SET telefone = '$telefone' WHERE matricula = '$matricula'"); echo "Alteração realizada com sucesso!"; ?> </body> </html>