Jump to content
Fórum Script Brasil
  • 0
Ferreira_Filho

Update múltiplos registros com checkbox

Question

Estou tentando fazer um update de vários registros com checkbox, mais não está atualizando no banco de dados MySQL. Segue o meu código, desde já agradeço!

<?php 
include_once("../config/conexao.php");
$nivel = $_SESSION['nivel'];
   
if ($_SESSION['nivel'] == 4)
    {
$sql = "SELECT ID, NOME, VOLUNTARIO FROM cidadao ORDER BY NOME";
$res = mysql_query($sql) or die (mysql_error() );

if (mysql_num_rows($res) > 0 )
echo '<form method="post">';
?>
<table width="431" border="0" align="center" cellpadding="0" class="bordaFina">
    <tr bgcolor="#999999" >
      <td width="302" align="center" valign="middle" bgcolor="#F0F0F0" class="style27">Nome  </td>
      <td width="123" align="center" valign="middle" bgcolor="#F0F0F0" class="style27">Voluntário</td>
    </tr>
    <?php
while ($row = mysql_fetch_assoc($res))
    {     
    ?>
    <tr >
      <td><?php echo $row["NOME"];?></div></td>
  <td ><div align="center"> 
 <input type="checkbox" name= "VOLUNTARIOS[<?php  $row["ID"] ?>]" value="1" <?php if($row["VOLUNTARIO"] == 1){ echo "checked";} ?>> 
 <input type="hidden" name= "VOLUNTARIOS[<?php $row["ID"] ?>]" value="0" <?php if($row["VOLUNTARIO"] == 0){ echo ""; }  ?>>
  </div></td>
  </tr>
    <?php 
  }  //End While
  ?>
</table>
  
<p><div align="center"><?php echo '<input type="submit"name= "submit" value= "Salvar">';?></div>
  <?php

if (isset ($_POST["submit"]))
{        
        foreach($_POST['VOLUNTARIOS'] as $ID => $VOL) 
          {mysql_query("update cidadao SET VOLUNTARIO ='$VOL' WHERE ID='$ID'")or die(mysql_error()); }                    
           echo "<meta HTTP-EQUIV='refresh' CONTENT='1;URL=teste.php'>";
}
?>
<?php
echo'<br>';
echo '</form>';
}//endif
?>

form.PNG

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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
      148558
    • Total Posts
      644318
×
×
  • Create New...