Select with repeated attributes

0

I'm having trouble writing to two different fields of a table using a <select> that has two attributes name and <options> with two value . >

I used the following code, but it only recorded the first name with its 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>

Is it possible to write two values in different fields using Select? if so, how?

    
asked by anonymous 05.11.2015 / 21:40

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 long code inside the attribute;

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

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

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

And within PHP you could do the verification:

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

That way it gets more organized and less error-prone.

    
05.11.2015 / 21:52