Jump to content
Fórum Script Brasil
  • 0

Recuperar checkbox do MySQL


MagoDanger

Question

Pessoal, estou recuperando os dados gravados no BD (MySQL) para poder editá-los, todos os campos estão retornando os valores certinhos, porém não consigo recuperar os checkbox que foram marcados. Alguém pode me dar essa forcinha?

Segue abaixo o código da minha página:

<?php

include "sql.php";
if(isset($_POST['done'])){

    $id = $_POST['id']; 
    $nome = $_POST['nome'];
        $data_cadastro = $_POST['data_cadastro'];
        $n_cadastro = $_POST['n_cadastro'];
        $rg = $_POST['rg'];
        $cpf = $_POST['cpf'];
        $data_niver = $_POST['data_niver'];
        $endereco = $_POST['endereco'];
        $n = $_POST['n'];
        $bairro = $_POST['bairro'];
        $cidade = $_POST['cidade'];
        $cep = $_POST['cep'];
        $telefone = $_POST['telefone'];
        $celular = $_POST['celular'];
        $email = $_POST['email'];
        $bra = $_POST['bra'];
        $situacao = $_POST['situacao'];
        $obs = $_POST['obs'];
        $aero = $_POST['aero'];
        
          
       $sql = mysql_query("UPDATE tbl_cadastro SET nome='$nome', data_cadastro='$data_cadastro', n_cadastro='$n_cadastro', rg='$rg', cpf='$cpf', data_niver='$data_niver', endereco='$endereco', n='$n', bairro='$bairro', cidade='$cidade', cep='$cep', telefone='$telefone', celular='$celular', email='$email', bra='$bra', situacao='$situacao', obs='$obs', aero='$aero'  WHERE id='$id'")or die(mysql_error());
           $linha = mysql_affected_rows();
            if($linha == 1){
                $erro = "Dados alterados com sucesso!";
              } else{
                  $erro = "Não foi possivel alterar os dados";
              }
}
$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM tbl_cadastro WHERE id = '$id'");
$nome = @mysql_result($sql, 0, "nome");
$data_cadastro = @mysql_result($sql, 0, "data_cadastro");
$n_cadastro = @mysql_result($sql, 0, "n_cadastro");
$rg = @mysql_result($sql, 0, "rg");
$cpf = @mysql_result($sql, 0, "cpf");
$data_niver = @mysql_result($sql, 0, "data_niver");
$endereco = @mysql_result($sql, 0, "endereco");
$n = @mysql_result($sql, 0, "n");
$bairro = @mysql_result($sql, 0, "bairro");
$cidade = @mysql_result($sql, 0, "cidade");
$cep = @mysql_result($sql, 0, "cep");
$telefone = @mysql_result($sql, 0, "telefone");
$celular = @mysql_result($sql, 0, "celular");
$email = @mysql_result($sql, 0, "email");
$bra = @mysql_result($sql, 0, "bra");
$situacao = @mysql_result($sql, 0, "situacao");
$obs = @mysql_result($sql, 0, "obs");
$aero = @mysql_result($sql, 0, "aero");

?>

<style type="text/css">
.campo{
width:400px;
}
.style2 {font-family: verdana}
.style8 {font-size: 12px}
.style9 {font-size: 11px}
</style>
<form name="form1" action="atualagenda.php" method="POST" style="padding-top:40px;">
<?php
if(isset($erro)){
    print '<div style="width:80%; background:#ff6600; color:#fff; padding: 5px 0px 5px 0px; text-align:center; margin: 0 auto;">'.$erro.'</div>';
}
?>
<table border="0" width="80%"  bgcolor="#f0f0f0" style="border:1px solid #ccc; margin:0 auto; position:relative;">
<thead>
<tr>
<th colspan="2">.:: Atualizar Ficha de Cadastro ::.</th>
</tr>
<tr>
  <td width="14%"><span class="style8 style2"><strong><strong>Data do Cadastro</strong></strong></span></td>
  <td width="86%" class="style9 style2 style9">
    <label>
    <input name="data_cadastro" type="text" id="data_cadastro" value="<?php echo $data_cadastro; ?>" size="15" maxlength="10" />
    <em>(Ex.: 00/00/0000)</em></label>
  </td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>N&ordm; Cadastro</strong></strong></span></td>
  <td><input name="n_cadastro" type="text" class="style2 style9" id="n_cadastro" value="<?php echo $n_cadastro; ?>" size="16" maxlength="16" /></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Nome</strong></strong></span></td>
  <td><span class="style9 style2 style9">
    <label>
    <input name="nome" type="text" id="nome" value="<?php echo $nome; ?>" size="70" maxlength="70" />
    </label>
  </span></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>RG</strong></strong></span></td>
  <td class="style9 style2 style9">
    <input name="rg" type="text" id="rg" value="<?php echo $rg; ?>" size="18" maxlength="18" />
      <em>(Ex.: 00.000.000-0)</em></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>CPF</strong></strong></span></td>
  <td class="style9 style2 style9">
    <input name="cpf" type="text" id="cpf" value="<?php echo $cpf; ?>" size="18" maxlength="18" />
      <em>(Ex.: 000.000.000-00)</em></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Data de Anivers&aacute;rio</strong></strong></span></td>
  <td class="style9 style2 style9">
    <label>
    <input name="data_niver" type="text" id="data_niver" value="<?php echo $data_niver; ?>" size="15" maxlength="10" />
    <em>(Ex.: 00/00/0000)</em></label>
  </td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Endere&ccedil;o</strong></strong></span></td>
  <td><span class="style9 style2 style9">
    <label>
    <input name="endereco" type="text" id="endereco" value="<?php echo $endereco; ?>" size="90" maxlength="90" />
    </label>
  </span></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>N</strong></strong></span></td>
  <td><span class="style9 style2 style9">
    <label>
    <input name="n" type="text" id="n" value="<?php echo $n; ?>" size="10" maxlength="10" />
    </label>
  </span></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Bairro</strong></strong></span></td>
  <td><span class="style9 style2 style9">
    <label>
    <input name="bairro" type="text" id="bairro" value="<?php echo $bairro; ?>" size="40" maxlength="40" />
    </label>
  </span></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Cidade</strong></strong></span></td>
  <td><span class="style9 style2 style9">
    <label>
    <input name="cidade" type="text" id="cidade" value="<?php echo $cidade; ?>" size="35" maxlength="35" />
    </label>
  </span></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>CEP</strong></strong></span></td>
  <td class="style9 style2 style9">
    <label>
    <input name="cep" type="text" id="cep" value="<?php echo $cep; ?>" size="10" maxlength="10" />
    <em>(Ex.: 000000-000)</em></label>  </td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Telefone</strong></strong></span></td>
  <td class="style9 style2 style9">
    <label>
    <input name="telefone" type="text" id="telefone" value="<?php echo $telefone; ?>" size="15" maxlength="15" />
    <em>(Ex.: (00) 0000-0000)</em></label>
  </td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Celular</strong></strong></span></td>
  <td class="style9 style2 style9">
    <input name="celular" type="text" id="celular" value="<?php echo $celular; ?>" size="15" maxlength="15" />
      <em>(Ex.: (00) 0000-0000)</em></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>E-Mail</strong></strong></span></td>
  <td><span class="style9 style2 style9">
    <label>
    <input name="email" type="text" id="email" value="<?php echo $email; ?>" size="85" maxlength="85" />
    </label>
  </span></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>BRA</strong></strong></span></td>
  <td><input name="bra" type="text" class="style2 style9" id="bra" value="<?php echo $bra; ?>" size="35" maxlength="35" /></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Modalidades</strong></strong></span></td>
  <td><span class="style9 style2 style9">
    <label> <strong>
    <input name="aero" type="checkbox" id="aero" value="<?php echo $aero; ?>" />
    Aeromodelismo
    <input name="heli" type="checkbox" id="heli" value="on" />
    Helimodelismo
    <input name="vcc" type="checkbox" id="vcc" value="on" />
    V.C.C.
    <input name="auto" type="checkbox" id="auto" value="on" />
    Automodelismo</strong></label>
  </span></td>
</tr>
<tr>
  <td><span class="style8 style2"><strong><strong>Situa&ccedil;&atilde;o Financeira</strong></strong></span></td>
  <td><input name="situacao" type="text" class="style2 style9" id="situacao" value="<?php echo $situacao; ?>" size="90" maxlength="90" /></td>
</tr>
<tr>
  <td><p class="style2 style8"><strong>Observa&ccedil;&otilde;es</strong></p>
      <p class="style2 style8">&nbsp;</p>
    <p class="style2 style8">&nbsp;</p>
    <p class="style2 style8">&nbsp;</p>
    <p class="style2 style8">&nbsp;</p></td>
  <td><span class="style2 style9">
    <label>
    <textarea name="obs" id="obs" cols="90" rows="10"><?php echo $obs; ?></textarea>
    </label>
  </span></td>
</tr>
</thead>
<tbody>
<tr>
  <td colspan="2">&nbsp;</td>
  </tr>
<tr>
<td></td>
<td><input type="submit" value="Atualizar Cadastro" />
  <input type="button" name="button" id="button" onclick="java script:location.href='edicao.php';" value="Cancelar" />
   <input type="button" name="button" id="button" onclick="java script:location.href='edicao.php';" value="Voltar" />
  <input type="hidden" name="done" value="" /><input name="id" type="hidden" value="<?php echo $id; ?>" /></td>
</tr>
</tbody>
</table>
</form>

Obrigado pessoal!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

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
      152.2k
    • Total Posts
      652k
×
×
  • Create New...