Ir para conteúdo

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Enlibra

Editar Tabela PHP MySQL

Recommended Posts

OláTenho o seguinte código:primeiro.php

<?include"conexao.php";$sgl = mysql_query("SELECT * FROM tb_clientes"); // código sgl que selecciona a tabela com os dados ?><table width=100% border="1" cellspacing=0 cellpading=0><? while($dados = mysql_fetch_array($sgl)) {?> <tr> <td width="5%"><? echo $dados['codigo']; ?></td> <td width="22%" class="noticias"><? echo $dados['nome']; ?></td> <td width="46%"><? echo $dados['endereco']; ?></td> <td width="14%"><? echo $dados['cidade']; ?></td> <td width="13%"><? echo $dados['estado']; ?></td> </tr><? }?></table>

que me vai buscar dados da tb_clientes e queria colocar em cada linha de registo um link para “editar” esse mesmo registo. Já tenho a pagina onde faço a edição do mesmo “altera.php”:

<?include"conexao.php";$sql = mysql_query("SELECT * from tb_clientes Where codigo=$id"); if(!$sql){echo mysql_error();exit();}?></head><body><form action="update.php" method="get" name="Teste"><?while($linha=mysql_fetch_array($sql)) {?><table width="984" border="1"> <tr> <td width="19">ID:</td> <td width="30"><input name="ID" type="text" value="<?=$linha["codigo"]?>" size="5" readonly="true"></td> <td width="41">Nome:</td> <td width="182"><input name="Nome" type="text" value="<?=$linha["nome"]?>" size="30"></td> <td width="336"><input name="Endereco" type="text" value="<?=$linha["endereco"]?>" size="30"></td> <td width="336"><input name="Cidade" type="text" value="<?=$linha["cidade"]?>" size="30"></td> </tr></table><?}?><p> <input type="submit" name="Submit" value="Submit"></p></form><?mysql_close($con);?>

Não sei como fazer na pagina “primeiro.php” para que me assuma o registo que quero alterar e passe o mesmo para a pagina altera.phpAlguém me pode ajudar?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu fiz como disse, mas aparece a seguinte mensagem:

You have an error in your SQL syntax near '' at line 1
A Página altera.php é:

<?include"conexao.php";$sql = mysql_query("SELECT * from tb_clientes Where codigo=$id"); if(!$sql){echo mysql_error();exit();}?></head><body><form action="update.php" method="get" name="Teste"><?while($linha=mysql_fetch_array($sql)) {?><table width="984" border="1"> <tr> <td width="19">ID:</td> <td width="30"><input name="ID" type="text" value="<?=$linha["codigo"]?>" size="5" readonly="true"></td> <td width="41">Nome:</td> <td width="182"><input name="Nome" type="text" value="<?=$linha["nome"]?>" size="30"></td> <td width="336"><input name="Endereco" type="text" value="<?=$linha["endereco"]?>" size="30"></td> <td width="336"><input name="Cidade" type="text" value="<?=$linha["cidade"]?>" size="30"></td> </tr></table><?}?><p> <input type="submit" name="Submit" value="Submit"></p></form><?mysql_close($con);?>

O que está errado?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.