Risultati da 1 a 3 di 3

Discussione: checkbox PHP

  1. #1
    Utente Senior L'avatar di GIH@cker
    Data Registrazione
    Oct 2007
    Località
    Catania
    Messaggi
    855

    checkbox PHP

    Ciao ragazzi, sto iniziando a studiare un pò di php e mysql ma ho un problema!
    Fra qualche giorno devo fare esami e nn ho ancora pronto un sito

    Dovrei fare un pannello di amministrazione con un form di checkbox con tutte le aziende da approvare e poi lanciare una query di aupdate che cambia il valore da 0 a 1. Ho scritto questo codice ma non funziona, coome mai?cosa devo sistemare?grazie a tt quelli che mi pox essere d'aiuto

    Codice:
    <form method="post">
    <?php 
    $cat = mysql_query("SELECT NomeAzienda FROM Aziende WHERE Approvata = 0 ORDER BY NomeAzienda ASC");
    
    $i = 0;
    while ($row = mysql_fetch_row($cat))
    {
    echo "<input type='checkbox' name='Approva[$i]' value='".$row['NomeAzienda']."'>".$row['NomeAzienda'];
    $i++;
    } 
    
    ?> 
    <input type="submit" name="submit" value=" Approva Azienda ">
    </form>
    
    <?php
    if (isset($_POST['submit']))
    {
    $myCheck = $_POST['Approva']; 
    foreach ($myCheck as $key => $value)
    {
    $acc = "UPDATE Aziende SET Approvata = 1 WHERE NomeAzienda = '$value' ";
    mysql_query($acc) or die (mysql_error());
    }
    }
    ?>



  2. #2
    Utente Senior L'avatar di GIH@cker
    Data Registrazione
    Oct 2007
    Località
    Catania
    Messaggi
    855

    Heeeeelpppp!!!!


  3. #3
    Utente Senior L'avatar di GIH@cker
    Data Registrazione
    Oct 2007
    Località
    Catania
    Messaggi
    855

    Ho risolto e metto a disposizione della community la soluzione!!!

    <form method="post">

    <?php
    if (isset($_POST['submit']))
    {
    $myCheck = $_POST[Approva];
    foreach ($myCheck as $key => $value)
    {
    $acc = "UPDATE Aziende SET Approvata = 1 WHERE NomeAzienda = '$value' ";
    mysql_query($acc) or die (mysql_error());
    }
    }
    ?>

    <?php
    $cat = mysql_query("SELECT NomeAzienda FROM Aziende WHERE Approvata=0")or die(mysql_error());

    $num_rows = 0;

    while (($row = mysql_fetch_array($cat)))
    {
    $NomeAzienda = $row['NomeAzienda'];
    echo "<input type = 'checkbox' name = 'Approva[$num_rows]' value = \"$NomeAzienda\">$NomeAzienda<br />";
    $num_rows++;
    }

    if ($num_rows > 0)
    echo "<input type='submit' name='submit' value='Approva Azienda'></form>"

    ?>


  4. L'utente di EG dice.. "Grazie!" a GIH@cker per questo Post:

    pistrim (21-01-22)

Tag per Questa Discussione

Segnalibri

Permessi di Scrittura

  • Tu non puoi inviare nuove discussioni
  • Tu non puoi inviare risposte
  • Tu non puoi inviare allegati
  • Tu non puoi modificare i tuoi messaggi
  •