Select with repeated attributes

Asked

Viewed 258 times

1

I’m having trouble recording in two different fields of a table using one <select> that has two attributes name and <options> with two value.

I used the code below, but it only recorded the first name with their respective value:

<div align="center" style=" padding:2px; border-right:solid 1px;float:left; width:210px; height:auto; float:left;">
   <?php
       include '../conexao.php';
       $codigo = $_POST['codigo'];
       $noticia = $_POST['noticia'];
       $habi_noticia = $_POST['habi_noticia'];
       $query = mysql_query("SELECT * FROM menu");
       $res = mysql_fetch_array($query);

       if(isset($_POST['noti'])){
           $noticia = $_POST['noticia'];
           $habi_noticia = $_POST['habi_noticia'];
           $update = mysql_query("UPDATE menu SET noticia = '$noticia', habi_noticia = '$habi_noticia'");

           if($update == ''){
               echo "
                   <script language='javascript'>
                       window.alert('Erro ao Habilitar Link Noticias!');
                   </script>";
           } else{
               echo "
                   <meta http-equiv='refresh' content='0; URL= menu_halitar_link.php'>
                   <script language='javascript'>
                       window.alert('Link Noticias Habilitado com sucesso!');
                   </script>";
           }
       }
   ?>

   <form name="noti" action="" method="POST" enctype="multipart/form-data">
       <label>Habilitar o Link Noticias?</label><br /><br />
       <select name="noticia" | name="habi_noticia" >
           <option value='<li><a href="<?php echo $res['dominio'];?>noticias.php" class="nav1">Noticias</a></li><li class="divider"></li>' | value='Sim'>Sim</option>
           <option value="" | value="Não">Não</option>
       </select><input type="submit" name="noti" value="Atualizar" />
   </form>
</div>

Can you save two values in different fields using Select? If so, how?

  • which select you’re talking about?

  • Just use a value and name for tags, with content redundancy you won’t be able to capture the values correctly.

1 answer

0

There are some things in your code that you should avoid.

  • Do not set the same attribute 2 times;
  • Do not use a very large code within the attribute;

An attribute defined 2 times will have as valid always the last to be defined, ie the first value will be ignored.

To achieve your goal, it would be easier to move this check to the backend, in your case to the PHP, for example:

<select name="noticia>
   <option value="1">Sim</option>
   <option value="2">Não</option>
</select>

And within the PHP you could do the check:

if ($noticia == 1) {
    //codigo com link da notícia
} else {
    //Faça a outra definição aqui
};

In this way it becomes more organized and less prone to errors.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.