Jump to content


Photo

Editar Banco De Dados


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

#1 ljrbrasil

ljrbrasil

    Turista

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

Posted 30/12/2011, 21:42

alguem pode me dizer o que esta errado? clico em editar apresenta a tela mas parece que nao link ao banco de dados.


arquvio Editar
<?php
@ini_set('display_errors', '1');
error_reporting(E_ALL);

$acesso = $_GET["acesso"];
settype($id, "integer");


mysql_connect("localhost", "root", "senha");
mysql_select_db("BDBD");

$resultado = mysql_query("select * from livrodevisitas where acesso = $acesso");
$dados     = mysql_fetch_array($resultado);

mysql_close();
?>


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="93%" border="0" align="center">
  <tr> 
    <td width="668"><div align="center" class="te_preto"> AREA RESTRITA </div></td>
  </tr>
  <tr> 
    <td height="586"> <p align="left"> </p>
      <form id="form1" name="form1" method="post" action="salvar_edicao.php">
        <input type="hidden" name="acesso" acesso="acesso" value="<?php echo $id;?>" />
        <h2 align="center"><strong>Edição de Cadastro PHP/MYSQL</strong></h2>
        <p align="center">&nbsp;</p>
        <table width="295" border="0" align="center" id="table1" style="border-collapse: collapse">
          <tr> 
            <td width="131" height="33"> <p align="left"><font face="Century Gothic" size="2">Filial:</font></td>
            <td width="154"> <p align="left" style="margin-top: 3px"><font face="Century Gothic" size="2"> 
                <input name="filial" type="text" id="filial" value="<?php echo $dados["filial"];?>" />
                </font></td>
          </tr>
          <tr> 
            <td height="15"><div align="left"><font face="Century Gothic" size="2">Regional: 
                </font></div></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <select name="regional" size="1" >
                <option>Selecione</option>
                <option value="<?php echo $dados["regional"];?>" />>Minas Gerais 
                <option value="<?php echo $dados["regional"];?>" />Rio de Janeiro 
                <option value="<?php echo $dados["regional"];?>" />Espirito Santo 
                <option value="<?php echo $dados["regional"];?>" />Bahia 
                <option value="<?php echo $dados["regional"];?>" />Centro Oeste 
              </select>
              </font></td>
          </tr>
          <tr> 
            <td height="30"><font face="Century Gothic" size="2">Pedido: </font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="regional" type="text" id="regional" value="<?php echo $dados["regional"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="35"><font face="Century Gothic" size="2">Data da Pedido:</font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="pedido" type="text" id="pedido" value="<?php echo $dados["pedido"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="35"><div align="left"><font face="Century Gothic" size="2">Data 
                da Ativa&ccedil;&atilde;o:</font></div></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="dtpedido" type="text" id="dtpedido" value="<?php echo $dados["dtpedido"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="31"><font size="2" face="Century Gothic">N&ordm; Acesso:</font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="cliente" type="text" id="cliente" value="<?php echo $dados["cliente"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="28"><div align="left"><font face="Century Gothic" size="2">Nome 
                Cliente:</font></div></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="cliente" type="text" id="cliente" value="<?php echo $dados["cliente"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="31"><font size="2" face="Century Gothic">CPF:</font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="cpf" type="text" id="cpf" value="<?php echo $dados["cpf"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="36"><div align="left"><font size="2" face="Century Gothic">Plano:</font></div></td>
            <td width="154"><select name="plano" >
                <option value="<?php echo $dados["plano"];?>" />Bandal Larga 
                <option value="<?php echo $dados["plano"];?>" />Recarga Programada 
              </select></td>
          </tr>
          <tr> 
            <td height="24"> <p align="left"><font size="2" face="Century Gothic">Backoffice</font></td>
            <td><select name="backoffice" size="1" >
                <option value="<?php echo $dados["backoffice"];?>" />Selecione 
                <option value="<?php echo $dados["backoffice"];?>" />Fernanda M 
                <option value="<?php echo $dados["backoffice"];?>" />Fernanda T 
                <option value="<?php echo $dados["backoffice"];?>" />Marcos 
                <option value="<?php echo $dados["backoffice"];?>" />Rafael 
                <option value="<?php echo $dados["backoffice"];?>" />Stephanie 
                <option value="<?php echo $dados["backoffice"];?>" />Milene 
                <option value="<?php echo $dados["backoffice"];?>" />Henrique 
                <option value="<?php echo $dados["backoffice"];?>" />Shirley 
                <option value="<?php echo $dados["backoffice"];?>" />Juliana 
                <option value="<?php echo $dados["backoffice"];?>" />Marlene </select> 
            </td>
          </tr>
          <tr> 
            <td height="24"><div align="center"> 
                <input type="submit" value="Enviar Vendas" name="B12">
              </div></td>
            <td><div align="center"> 
                <input type="reset" value="Limpar dados" name="B22">
              </div></td>
          </tr>
          <tr> 
            <td height="24" colspan="2"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="painel.php">Retornar 
                ao Menu</a></font></div></td>
          </tr>
        </table>
        <p align="center">&nbsp;</p>
      </form></td>
  </tr>
</table>
</body>
</html>


Salva_edicao
<?php
@ini_set('display_errors', '1');
error_reporting(E_ALL);

$filial      =  $_POST ['filial'];
$regional    =  $_POST ['regional'];
$pedido      =  $_POST ['pedido'];
$dtpedido    =  $_POST ['dtpedido'];
$data        =  $_POST ['data'];
$acesso      =  $_POST ['acesso'];
$cliente     =  $_POST ['cliente'];
$cpf         =  $_POST ['cpf'];
$plano       =  $_POST ['plano'];
$backoffice  =  $_POST ['backoffice'];
 
mysql_connect("localhost", "root", "senha");
mysql_select_db("bDBD");

mysql_query("UPDATE livrodevisitas SET filial = '$filial', regional = '$regional', pedido = '$pedido', dtpedido = '$dtpedido', data = '$data', acesso = '$acesso', cliente = '$cliente', cpf = '$cpf', plano = '$plano', backoffice = '$backoffice' WHERE livrodevisitas.acesso= $id");
mysql_close();
header("Location: leitura.php");
?>



#2 ljrbrasil

ljrbrasil

    Turista

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

Posted 02/01/2012, 17:45

e ai? alguem me ajuda nesta?

#3 Goku Jr

Goku Jr

    Nilson

  • Usuários
  • 3757 posts
  • Sexo:Masculino

Posted 02/01/2012, 19:06

O que não linka? quando vc vai salvar no banco de dados ou quando vc abre a tela pra editar? apresenta alguma mensagem de erro?

experimenta adicionar um echo na função mysql_error(); ou or die mysql_error();



T+
-----------------------------------------------------------------------
PALMEIRAS - Primeiro campeão do mundo em 1951

#4 ljrbrasil

ljrbrasil

    Turista

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

Posted 02/01/2012, 21:29

Goku Jr

obrigado pela ajuda poderia exemplificar?

fico grato desde ja.

#5 Goku Jr

Goku Jr

    Nilson

  • Usuários
  • 3757 posts
  • Sexo:Masculino

Posted 03/01/2012, 07:00

Não está retornando nenhuma mensagem de erro?


Sobre o mysql_error();


mysql_connect("localhost", "root", "senha") or die (mysql_error());
mysql_select_db("BDBD") or die (mysql_error());

$resultado = mysql_query("select * from livrodevisitas where acesso = {$acesso}") or die (mysql_error());
$dados = mysql_fetch_array($resultado) or die (mysql_error());

-----------------------------------------------------------------------
PALMEIRAS - Primeiro campeão do mundo em 1951

#6 ljrbrasil

ljrbrasil

    Turista

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

Posted 03/01/2012, 07:12

Goku Jr

Como disse nao esta apresentando nenhum erro. simplismente quando clico em editar ele carrega somente dados de uma linha do banco e nao da linha selecionada veja Clique aqui

segue o codigo com as alteraçoes que voce falou veja.


<?php
@ini_set('display_errors', '1');
error_reporting(E_ALL);

$id = $_GET["filial"];
settype($id, "integer");


mysql_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("BDBD")or die (mysql_error());

$resultado = mysql_query("select * from livrodevisitas where filial = $id") or die (mysql_error());
$dados     = mysql_fetch_array($resultado) or die (mysql_error());

mysql_close();
?>


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="93%" border="0" align="center">
  <tr> 
    <td width="668"><div align="center" class="te_preto"> AREA RESTRITA </div></td>
  </tr>
  <tr> 
    <td height="586"> <p align="left"> </p>
      <form id="form1" name="form1" method="post" action="salvar_edicao.php">
        <input type="hidden" name="acesso" acesso="acesso" value="<?php echo $id;?>" />
        <h2 align="center"><strong>Edição de Cadastro PHP/MYSQL</strong></h2>
        <p align="center">&nbsp;</p>
        <table width="295" border="0" align="center" id="table1" style="border-collapse: collapse">
          <tr> 
            <td width="131" height="33"> <p align="left"><font face="Century Gothic" size="2">Filial:</font></td>
            <td width="154"> <p align="left" style="margin-top: 3px"><font face="Century Gothic" size="2"> 
                <input name="filial" type="text" id="filial" value="<?php echo $dados["filial"];?>" />
                </font></td>
          </tr>
          <tr> 
            <td height="15"><div align="left"><font face="Century Gothic" size="2">Regional: 
                </font></div></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <select name="regional" size="1" >
                <option>Selecione</option>
                <option value="<?php echo $dados["regional"];?>" />>Minas Gerais 
                <option value="<?php echo $dados["regional"];?>" />Rio de Janeiro 
                <option value="<?php echo $dados["regional"];?>" />Espirito Santo 
                <option value="<?php echo $dados["regional"];?>" />Bahia 
                <option value="<?php echo $dados["regional"];?>" />Centro Oeste 
              </select>
              </font></td>
          </tr>
          <tr> 
            <td height="30"><font face="Century Gothic" size="2">Pedido: </font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="regional" type="text" id="regional" value="<?php echo $dados["regional"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="35"><font face="Century Gothic" size="2">Data da Pedido:</font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="pedido" type="text" id="pedido" value="<?php echo $dados["pedido"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="35"><div align="left"><font face="Century Gothic" size="2">Data 
                da Ativa&ccedil;&atilde;o:</font></div></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="dtpedido" type="text" id="dtpedido" value="<?php echo $dados["dtpedido"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="31"><font size="2" face="Century Gothic">N&ordm; Acesso:</font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="cliente" type="text" id="cliente" value="<?php echo $dados["cliente"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="28"><div align="left"><font face="Century Gothic" size="2">Nome 
                Cliente:</font></div></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="cliente" type="text" id="cliente" value="<?php echo $dados["cliente"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="31"><font size="2" face="Century Gothic">CPF:</font></td>
            <td width="154"><font face="Century Gothic" size="2"> 
              <input name="cpf" type="text" id="cpf" value="<?php echo $dados["cpf"];?>" />
              </font></td>
          </tr>
          <tr> 
            <td height="36"><div align="left"><font size="2" face="Century Gothic">Plano:</font></div></td>
            <td width="154"><select name="plano" >
                <option value="<?php echo $dados["plano"];?>" />Bandal Larga 
                <option value="<?php echo $dados["plano"];?>" />Recarga Programada 
              </select></td>
          </tr>
          <tr> 
            <td height="24"> <p align="left"><font size="2" face="Century Gothic">Backoffice</font></td>
            <td><select name="backoffice" size="1" >
                <option value="<?php echo $dados["backoffice"];?>" />Selecione 
                <option value="<?php echo $dados["backoffice"];?>" />Fernanda M 
                <option value="<?php echo $dados["backoffice"];?>" />Fernanda T 
                <option value="<?php echo $dados["backoffice"];?>" />Marcos 
                <option value="<?php echo $dados["backoffice"];?>" />Rafael 
                <option value="<?php echo $dados["backoffice"];?>" />Stephanie 
                <option value="<?php echo $dados["backoffice"];?>" />Milene 
                <option value="<?php echo $dados["backoffice"];?>" />Henrique 
                <option value="<?php echo $dados["backoffice"];?>" />Shirley 
                <option value="<?php echo $dados["backoffice"];?>" />Juliana 
                <option value="<?php echo $dados["backoffice"];?>" />Marlene </select> 
            </td>
          </tr>
          <tr> 
            <td height="24"><div align="center"> 
                <input type="submit" value="Enviar Vendas" name="id">
              </div></td>
            <td><div align="center"> 
                <input type="reset" value="Limpar dados" name="B22">
              </div></td>
          </tr>
          <tr> 
            <td height="24" colspan="2"><div align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="painel.php">Retornar 
                ao Menu</a></font></div></td>
          </tr>
        </table>
        <p align="center">&nbsp;</p>
      </form></td>
  </tr>
</table>
</body>
</html>


#7 Fernando_Ramos

Fernando_Ramos

    Fernando Ramos

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

Posted 03/01/2012, 09:59

Ele acessa o banco normalmente... acessa a tabela normalmente... mas tras o registro errado é isso?

Tenta printar o SQL na tela... copia e executa no Mysql.... pra ver o retorno...
--
www.ramosinformatica.com
contato@ramosinformatica.com | @rinformatica

Hospedagem de site | Desenvolvimento de Sistemas | Informática em Geral

#8 ljrbrasil

ljrbrasil

    Turista

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

Posted 03/01/2012, 19:05

Amigo Fernando

agradeço sua explicação, porem sou novato poderia explicar melhor?

#9 Fernando_Ramos

Fernando_Ramos

    Fernando Ramos

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

Posted 05/01/2012, 10:27

Onde está
$resultado = mysql_query("select * from livrodevisitas where filial = $id") or die (mysql_error());
$dados     = mysql_fetch_array($resultado) or die (mysql_error());

somente a base de teste muda para:

$Sql = "select * from livrodevisitas where filial = $id";
echo $Sql;
$resultado = mysql_query($Sql) or die (mysql_error());
$dados     = mysql_fetch_array($resultado) or die (mysql_error());

copia o printa na tela e joga no seu gerenciador do banco (PHPMYADMIN, .....) e vc se retorna o registro certinho ......


Mas vc não respondeu se esta conectando certinho.... e se esta trazendo algum resultado.. mas errado..... acho q o erro não esta no SQL... mas... testa ai...




outra coisa.... nesse teu SQL = select * from livrodevisitas where filial = $id

traz somente 1 registro? se retornar mais...precisará de um while....

Edição feita por: Fernando_Ramos, 05/01/2012, 10:29.

--
www.ramosinformatica.com
contato@ramosinformatica.com | @rinformatica

Hospedagem de site | Desenvolvimento de Sistemas | Informática em Geral

#10 shayllis

shayllis

    12 Horas

  • Usuários
  • 152 posts
  • Sexo:Masculino
  • Localidade:Barueri - SP
  • Interesses:PHP, MySQL, ASP.NET C# e VB, DreamWeaver, VisualStudio, JavaScript

Posted 05/01/2012, 20:41

Seu server parece que está configurado numa versão antiga também... Além de tudo o que foi dito... Nas versões atuais do PHP, a concatenação está um pouco diferente, você não usa mais uma variável desta forma $var = "texto $variavel"... seria algo como $var = "texto {$variavel}"... e o seu ini_set não é recomendado que se use, porque algum erro mais grave retornará erro 530... erro interno do servidor

Para percorrer do inicio ao fim da consulta faça da seguinte forma

while($resultado = mysql_fetch_assoc($query)){
?>
<table>
<tr>
<td>$redultado['campo do query']</td>
</tr>
</table>

<?php
}
?>


Você também pode adicionar alguns recursos a mais.




0 user(s) are reading this topic

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

IPB Skin By Virteq