View Full Version : [html - php - mysql]
ragazzi ho un problemino con una form e checkbox.
ho una lista di utenti "checkboxabili", tanti utenti. che aumenteranno.
è chiaro che nel POST della form non posso fare $x=$_POST['x'] per ogni checkbox, sarebbero tantissimi e dovrei mettere mano al codice ogni volta che aumentano.
devo poter avere i miei $_POST così da aggiornare il database con delle insert (o delete nel caso siano de-checkboxate)
mi aiutate?
sono arrivato alla conclusione quasi da solo, solo che:
<div id="contornoupload">
<div id="contornoupload" style="width:618px;">
<?php if(isset($_POST['Submituser'])){
$action=$_POST['action'];
$utente=$_POST['utente'];
if( is_array($utente) ) {
reset($utente);
while($elemento=next($utente)){
$result4=mysql_query("insert into tprivilegio (id_utente,id_prodotto)values('$elemento','$action')");
}
}
} ?>
<form action="questa pagina" method="post">
<?php $count=0;
$result=mysql_query("SELECT id, nome, cognome from tutenti order by id"); ?>
<div class="boxutenti">
<?php while($row=mysql_fetch_array($result)){
$id=$row['id'];
$nome=$row['nome'];
$cognome=$row['cognome'];
$result2=mysql_query("SELECT id_utente from tprivilegio where id_utente='$id'");
while($row2=mysql_fetch_array($result2)){$id_utente=$row2['id_utente'];} ?>
<input type="checkbox" style="width:auto;margin:5px 5px 0 5px;" name="utente[]" value="<?php echo $id; ?>" <?php if($id_utente==$id){ ?>checked="checked"<?php } ?> /><?php echo $cognome; ?> <?php echo $nome; ?><br/>
<?php $count++;
if($count%10==0) echo "</div><div class=\"boxutenti\">";
} ?>
</div>
<input type="hidden" value="<?php echo $action; ?>" name="action" id="action" />
<input type="submit" value="Save" class="bottone" style="width:auto;clear:both;float:right;" id="Submituser" name="Submituser"/></form>
</div>
</div>
l'array $utente contiene solo i value dei box checkati.... ma come faccio a fare che se un box non è checkato allora ci vuole una delete??? perchè con il $_POST non mi arrivano i non checkati, e io sò solo il numero max assoluto di checkbox
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.