Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Problema Panel control

  1. #1
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269

    Problema Panel control

    Buonasera ho praticametne creato un ceckbox ogni volta che viene aggiunto un utente e posso però solamente elimianre uno alla volta esempio se seleziono piu di uno mi cancella solo un utente come devo fare? ecco lo script:


    <?php

    $db_host="localhost";
    $db_name="XXX";
    $db_user="XXX";
    $db_password="";

    mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
    mysql_select_db($db_name) or die("errore database");

    $sql = "SELECT * FROM utenti ORDER BY nome";
    $result = mysql_query($sql);
    echo "
    <table border=\"1\">
    <tr>
    <th>ID</th><th>Nome</th><th>Cognome</th><th>Indirizzo</th><th>Cap</th><th>Citta</th><th>Telefono</th><th>Email</th><th>Nato</th><th>Cancella</th>
    </tr>
    ";
    while($row = mysql_fetch_array($result))
    {
    echo "
    <tr>
    <td>".$row['id']."</td><td>".$row['nome']."</td><td>".$row['cognome']."</td><td>".$row['indirizzo']."</td><td>".$row['cap']."</td><td>".$row['citta']."</td><td>".$row['telefono']."</td><td>".$row['email']."</td><td>".$row['nato']."</td><td style=\"text-align:center;\"><form action=\"cancella.php\" method=\"post\"><input type=\"checkbox\" name=\"cancella\" value=\"".$row['id']."\"></td>
    </tr>
    ";
    }

    echo "<td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td style=\"text-align:center;\"><input type=\"submit\" value=\"Cancella\"></td></form>";

    echo "
    </table>
    ";

    mysql_close();
    ?>


    Grazie
    Con i sogni possiamo conoscere il futuro...

  2. #2
    Utente di HTML.it
    Registrato dal
    Dec 2006
    Messaggi
    327
    non funzionerà mai perchè in questo modo non fai altro che attribuire a tutti gli utenti una checkbox con lo stesso nome, invece ognuno deve avere una checkbox che lo identifichi.
    Puoi benissimo, dopo aver la select che va a prendere tutti gli utenti del db, associare nome e numero ciclo ad ogni checkbox, cosi da poter renderle univoche per ogni utente.

    es.

    Codice PHP:

    <?php

    $db_host
    ="localhost";
    $db_name="XXX";
    $db_user="XXX";
    $db_password="";

    mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
    mysql_select_db($db_name) or die("errore database");

    $sql "SELECT * FROM utenti ORDER BY nome";
    $result mysql_query($sql);
    ?>

    <form action="cancella.php" method="post" name="form_delete">
      <table border="1">
        <tr>
          <th>ID</th>
          <th>Nome</th>
          <th>Cognome</th>
          <th>Indirizzo</th>
          <th>Cap</th>
          <th>Citta</th>
          <th>Telefono</th>
          <th>Email</th>
          <th>Nato</th>
          <th>Cancella</th>
        </tr>
        <?php 
    $count 
    mysql_num_rows($result);
    for (
    $i=0$i<$count$i++){
    $row mysql_fetch_array($result);
    {
    ?>
        <tr>
          <td><?php echo $row['id']; ?></td>
          <td><?php echo $row['nome']; ?></td>
          <td><?php echo $row['cognome']; ?></td>
          <td><?php echo $row['indirizzo']; ?></td>
          <td><?php echo $row['cap']; ?></td>
          <td><?php echo $row['citta']; ?></td>
          <td><?php echo $row['telefono']; ?></td>
          <td><?php echo $row['email']; ?></td>
          <td><?php echo $row['nato']; ?></td>
          <td style="text-align:center;"><input type="checkbox" name="cancella_<?php echo $i;?>" value="<?php echo $row['id']; ?>"></td>
        </tr>
        <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td style="text-align:center;"><input type="hidden" name="totale" value="<?php echo $count?>"><input type="submit" value="Cancella"></td>
      </table>
    </form>
    <?php

    mysql_close
    ();
    ?>
    Infine nella pagina di destinazione(cancella.php), metterai uno script cosi

    Codice PHP:

    <?php

    $db_host
    ="localhost";
    $db_name="XXX";
    $db_user="XXX";
    $db_password="";

    mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
    mysql_select_db($db_name) or die("errore database");

    $totale $_POST['totale'];

    for (
    $i=0$i<$totale$i++){

    if (!empty(
    $_POST['cancella'.$i])){

    $delete "delete from utenti where id = ".$_POST['cancella'.$i];
    mysql_query($delete);

    }

    }



    ?>

  3. #3
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269
    Mi s che c'è qualche errore siccome mi da questo:


    Parse error: syntax error, unexpected $end in /membri/fantaminei/tabella.php on line 68
    Con i sogni possiamo conoscere il futuro...

  4. #4
    Utente di HTML.it
    Registrato dal
    Dec 2006
    Messaggi
    327
    posta il codice delll'intera pagina

    PS.

    mi sono accorto di un piccolo errore sul codice che ti ho postato in precedenza, prova questo


    Codice PHP:

    <?php

    $db_host
    ="localhost";
    $db_name="XXX";
    $db_user="XXX";
    $db_password="";

    mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
    mysql_select_db($db_name) or die("errore database");

    $sql "SELECT * FROM utenti ORDER BY nome";
    $result mysql_query($sql);
    ?>

    <form action="cancella.php" method="post" name="form_delete">
      <table border="1">
        <tr>
          <th>ID</th>
          <th>Nome</th>
          <th>Cognome</th>
          <th>Indirizzo</th>
          <th>Cap</th>
          <th>Citta</th>
          <th>Telefono</th>
          <th>Email</th>
          <th>Nato</th>
          <th>Cancella</th>
        </tr>
        <?php 
    $count 
    mysql_num_rows($result);
    for (
    $i=0$i<$count$i++){
    $row mysql_fetch_array($result);

    ?>
        <tr>
          <td><?php echo $row['id']; ?></td>
          <td><?php echo $row['nome']; ?></td>
          <td><?php echo $row['cognome']; ?></td>
          <td><?php echo $row['indirizzo']; ?></td>
          <td><?php echo $row['cap']; ?></td>
          <td><?php echo $row['citta']; ?></td>
          <td><?php echo $row['telefono']; ?></td>
          <td><?php echo $row['email']; ?></td>
          <td><?php echo $row['nato']; ?></td>
          <td style="text-align:center;"><input type="checkbox" name="cancella_<?php echo $i;?>" value="<?php echo $row['id']; ?>"></td>
        </tr><?php }?>
        <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td></td>
          <td style="text-align:center;"><input type="hidden" name="totale" value="<?php echo $count?>"><input type="submit" value="Cancella"></td>
      </table>
    </form>
    <?php

    mysql_close
    ();
    ?>
    in ogni caso se dovesse darti errore ugualmente, postami il codice di tutta la pagina

  5. #5
    Utente di HTML.it L'avatar di gaten
    Registrato dal
    Jul 2007
    Messaggi
    1,269
    Niente ora però l'errore non me lo da ma quando provo a cnacellare tipo 3 utenti premo cancella e mi esce solo una pagina bianca e basta ecco i codici:


    <?php

    $db_host="localhost";
    $db_name="XXX";
    $db_user="XXX";
    $db_password="";

    mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
    mysql_select_db($db_name) or die("errore database");

    $sql = "SELECT * FROM utenti ORDER BY nome";
    $result = mysql_query($sql);
    ?>

    <form action="cancella.php" method="post" name="form_delete">
    <table border="1">
    <tr>
    <th>ID</th>
    <th>Nome</th>
    <th>Cognome</th>
    <th>Indirizzo</th>
    <th>Cap</th>
    <th>Citta</th>
    <th>Telefono</th>
    <th>Email</th>
    <th>Nato</th>
    <th>Cancella</th>
    </tr>
    <?php
    $count = mysql_num_rows($result);
    for ($i=0; $i<$count; $i++){
    $row = mysql_fetch_array($result);

    ?>
    <tr>
    <td><?php echo $row['id']; ?></td>
    <td><?php echo $row['nome']; ?></td>
    <td><?php echo $row['cognome']; ?></td>
    <td><?php echo $row['indirizzo']; ?></td>
    <td><?php echo $row['cap']; ?></td>
    <td><?php echo $row['citta']; ?></td>
    <td><?php echo $row['telefono']; ?></td>
    <td><?php echo $row['email']; ?></td>
    <td><?php echo $row['nato']; ?></td>
    <td style="text-align:center;"><input type="checkbox" name="cancella_<?php echo $i;?>" value="<?php echo $row['id']; ?>"></td>
    </tr><?php }?>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td style="text-align:center;"><input type="hidden" name="totale" value="<?php echo $count; ?>"><input type="submit" value="Cancella"></td>
    </table>
    </form>
    <?php

    mysql_close();
    ?>



    cancella.php:



    <?php

    $db_host="localhost";
    $db_name="my_fantaminei";
    $db_user="fantaminei";
    $db_password="";

    mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
    mysql_select_db($db_name) or die("errore database");

    $totale = $_POST['totale'];

    for ($i=0; $i<$totale; $i++){

    if (!empty($_POST['cancella'.$i])){

    $delete = "delete from utenti where id = ".$_POST['cancella'.$i];
    mysql_query($delete);

    }

    }



    ?>


    Con i sogni possiamo conoscere il futuro...

  6. #6
    Utente di HTML.it
    Registrato dal
    Dec 2006
    Messaggi
    327
    prova adesso

    cancella.php

    Codice PHP:

    <?php

    $db_host
    ="localhost";
    $db_name="XXX";
    $db_user="XXX";
    $db_password="";

    mysql_connect($db_host,$db_user,$db_password) or die("errore connessione");
    mysql_select_db($db_name) or die("errore database");

    $totale $_POST['totale'];

    for (
    $i=0$i<$totale$i++){

    if (!empty(
    $_POST['cancella_'.$i])){

    $delete "delete from utenti where id = ".$_POST['cancella_'.$i];
    mysql_query($delete);

    }

    }


    ?>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.