Jump to content
Fórum Script Brasil
  • 0

Problema no update mysql


Dimitrov

Question

Gostaria de saber porque não consigo alterar meus dados no mysql,o codigo esta certo,aparentemente pelo menos,pois é pra clicar no botao alterar e depois ele ir para o input ,dai pra mim alterar o nome dele.mas ele ao clicar em alterar ele não esta indo para o input =/

por favor alguém me de uma ajuda ai.

obrigado

Categoria.php

<?php include "conexao.php" ?>
<!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>
</head>

<body>
<table width="750" border="0" align="center">
  <tr>
    <td colspan="2"><?php include('cabecalho.php'); ?></td>
  </tr>
  <tr>
    <td width="200"><?php include('menu.php'); ?></td>
    <td width="583"><table width="100%" border="0">
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td align="center" style="font-size: 14px; text-align: center;"><p>categoria</p>
        
        <?php 
        
        if ($acao != "") {
            $sql = mysql_query ("SELECT * from Categorias Where id_categoria = $id"); ?>
        
            
          <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF ?>">
            <table width="300" border="1" align="center" cellpadding="2" cellspacing="0">
              <tr>
                <td width="143">Categoria</td>
                <td width="147"><label>
                  <input name="txt_categoria" type="text" id="txt_categoria" size="35" value= "<?php echo @mysql_result($sql,0,categoria); ?>"/>
                </label></td>
              </tr>
              <tr>
                <td colspan="2" align="center"><label>
                  <input type="submit" name="button" id="button" value="OK" />
                </label></td>
                </tr>
            </table>
          </form>
          <?php } else { ?>
          <table width="99%" border="1">
            <tr>
              <td width="90%" align="left">Categorias</td>
              <td colspan="2" align="center">Ação</td>
              </tr>
              <?php $sql = mysql_query ("SELECT * from categorias") or exit(mysql_error());
              while ($coluna = mysql_fetch_array ($sql)) { ?>
            <tr>
              <td align="left"><?php echo $coluna[categoria] ?></td>
              <td width="5%"><a href="?acao=Alterar&id= <?php echo $coluna[id_categoria];?>"><img src="imagens/b_edit.gif" width="16" height="16" border = "0"/></a></td>
              <td width="5%"><img src="imagens/b_drop.gif" width="16" height="16" /></td>
            </tr>
            <?php } ?>
            <tr>
              <td colspan="3" align="right"><img src="imagens/b_insrow.gif" width="16" height="16" /><span style="font-size: 12px;">Inserir</span></td>
              </tr>
          </table>
          <?php } ?>
          <p>&nbsp;</p></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td colspan="2"><?php include('rodape.php'); ?></td>
  </tr>
</table>
</body>
</html>
cabecalho.php
<table width="779" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%"  height="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="9%">&nbsp;</td>
        <td width="25%"><img src="imagens/logo.jpg" width="156" height="89" /></td>
        <td width="59%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td colspan="2">&nbsp;</td>
            </tr>
          <tr>
            <td width="73%">&nbsp;</td>
            <td width="27%"><img src="imagens/imagenadm.gif" width="169" height="40" /></td>
          </tr>
          <tr>
            <td colspan="2">&nbsp;</td>
            </tr>
          <tr>
            <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="33%"> login:</td>
                <td width="58%"><strong>Data:</strong><?php 
                $dia_da_semana = array ("Domingo","Segunda","Terça","Quarta","Quinta","Sexta","Sábado");
                $num_dia = date (w);
                $dia_extenso = $dia_da_semana[$num_dia];
                echo $dia_extenso.",  ".date("d/m/Y");?>
                - <b> Hora: </b>
                <?php echo date("H:i");   ?>
                - <b> IP: </b>
                <?php echo getenv ("REMOTE_ADDR"); ?>
        
                </td>
                <td width="9%">&nbsp;</td>
              </tr>
            </table></td>
            </tr>
          <tr>
            <td colspan="2"><img src="imagens/menu.gif" width="623" height="34" /></td>
            </tr>
        </table></td>
        <td width="7%">&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
menu.php
<table width="200" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="32">&nbsp;</td>
    <td width="131"></td>
    <td width="37">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><table width="178" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="imagens/menuu.gif" width="183" height="39" /></td>
      </tr>
      <tr>
        <td><table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
          <tr>
            <td width="11%" height="51">&nbsp;</td>
            <td width="89%" align="left" valign="top">
            <a href="categoria.php">Categorias </a> <br />
            <a href="subcategoria.php">Sub Categorias </a><br  />
            <a href="produtos.php">Produtos </a><br />
            <a href="clientes.php">Cliente </a><br />
           
            &nbsp;</td>
          </tr>
        </table></td>
      </tr>
    </table></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
conexao.php
<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_conexao = "localhost";
$database_conexao = "loja";
$username_conexao = "root";
$password_conexao = "";
$conexao = mysql_pconnect($hostname_conexao, $username_conexao, $password_conexao) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db( $database_conexao , $conexao ) or die( mysql_error() );
?>

Link to post
Share on other sites

6 answers to this question

Recommended Posts

  • 0
So vi SELECT ae não vi nenhum UPDATE, Se tiver UPDATE coloque ae como você fez o sql. =) Até mais!

verdade copie errado

o alterar ta ai...

<a href="?acao=Alterar&id= <?php echo $coluna[id_categoria] ;?>"><img src="imagens/b_edit.gif" width="16" height="16" border = "0"/></a>

valeu

Link to post
Share on other sites
  • 0

O que todos estão querendo dizer é ... vocão tem o comando de atualizar em seu código ....

Ele não atualiza só porque você clica em um link/botão você deve colocar essa ação exemplo ...

<?php
if (isset($_GET["acao"] == "Alterar") {
 // Conecat no Banco (essa parte você já sabe)

 // Atualiza ao Clicar link com os dados do Link
 mysql_query("UPDATE tabela SET campo='" . $_GET["novoValor"] . "' WHERE id=" . $_GET["id"]);
 echo "Atualizado com Sucesso!!!";
}
?>

<a href="?acao=Alterar&id=1&novoValor=Teste">[ALTERAR]</a>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148892
    • Total Posts
      644912
×
×
  • Create New...