Jump to content
Sign in to follow this  
N3lson

[Resolvido] Inserir dados (MULTI-SELECT)

Recommended Posts

N3lson

Boas estou a tentar adicionar dados de presenças de alunos através de seleção multipla.

O que está-me a dar é que apenas adiciona o 1º aluno os seguintes não são adicionados.

Aqui está o form

	    
$txt_var ='CONTROLE DE ASSIDUIDADE';
	  echo '
	  <div class="widget">
	    <div class="title"><h6>' .$txt_var .'</h6></div>
	    <form class="form" action="./sql/sql_compet.php" method="post">
	    <input name="go" value="pre_s" type="hidden"/>
	    <input name="id" value="on" type="hidden"/>
	    <p><label>listagem dos Atletas</label><select size="5" name="atleta_id[]" multiple="multiple">';
	   $users_id = mysqli_query($con, "SELECT id, nome FROM atletas");
	   while($r=mysqli_fetch_assoc($users_id)){
		   echo'<option value="'.$r['id'].'">'.$r['nome'].'</option>';
	   }
	  echo'</select></p>
	    <p><label>Presença:</label>
	    <select name="val">
	    <option value="0">Ausente</option>
	    <option value="1">Presente</option>
	    </select></p>	  
	    <p><label>Data:</label><input type="text" name="data" value="'.date('Y-m-d').'"  size="10" />
	    <input class="button" type="submit" value="Submeter"/>
	    </form></p></div>';

E aqui o sql

foreach($_POST['atleta_id'] as $id){
$query =  "INSERT INTO presencas VALUES (NULL, $id, '$_POST[data]', '$_POST[val]')";		    
mysqli_query($con, $query);
mysqli_close($con);
}
redirecionar('2','../administrar.php?faltas=true', 'DADOS ADICIONADOS');

O que estou a fazer de errado ?


You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites
HappyHippyHippo
foreach($_POST['atleta_id'] as $id){
 $query =  "INSERT INTO presencas VALUES (NULL, $id, '$_POST[data]', '$_POST[val]')";                
 mysqli_query($con, $query);
 mysqli_close($con); // <--- o que isto está aqui a fazer ?
}

  • Vote 1

IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites
N3lson

oops, não tinha reparado.

Isso deve-se a possuir num script a manipulação do sql através de switch [get(go)] fiz copy<->paste mas comno são independentes mas este é de mutiplo, passou-me ao lado.

Logo dou feedback...

Obrigado .

RESOLVIDO

Edited by N3lson

You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.