Jump to content


Photo

Alterar Php


  • Faça o login para participar
2 replies to this topic

#1 motta Junior

motta Junior

    Novato no fórum

  • Usuários
  • 7 posts
  • Sexo:Não informado

Posted 05/08/2008, 11:01

Olá queridos amigos...
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>


#2 Maykel Esser

Maykel Esser

    Super Veterano

  • Usuários
  • 1536 posts
  • Sexo:Masculino
  • Localidade:Curitiba - PR

Posted 05/08/2008, 11:16

retorna algum erro? já jogou essa consulta do update direto no banco pra ver se retorna?

Se este post lhe ajudou, ajude o fórum também. Use a reputação de mensagens! add.png


#3 motta Junior

motta Junior

    Novato no fórum

  • Usuários
  • 7 posts
  • Sexo:Não informado

Posted 05/08/2008, 15:59

Bom desde já agradeço a ajuda...
Já consegui resolver o problema.
Abraços.




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq