zioarnold Posted May 26, 2016 Share Posted May 26, 2016 <?php include "connetti.php"; session_start(); $query = "SELECT id_studente, nome, cognome, anno_maturita, voto_maturita FROM utenti_studenti WHERE utenti_studenti.confermato = 0"; $risultato = @mysql_query($query); if (mysql_num_rows($risultato) == 0) { echo("Nessun elemento trovato"); header("refresh:3;url=AreaAmministratore.phtml"); exit(); } ?> <html> <head> <title>Annuario Studenti</title> <link rel="stylesheet" href="cssUtils/aggiungi_properties.css"/> <script type="text/javascript" src="jsUtils/jsUtils_annuario/annuario_properties.js"></script> </head> <body> <form method='post' action='confermaStudenti.php' name='aggiornaStatoStudente'> <div align='center'> <table class='tg'> <tr> <th class='tg' style='color: #000;'>ID</th> <th class='tg' style='color: black'>Nome</th> <th class='tg' style='color: black'>Cognome</th> <th class='tg' style='color: black'>Anno Maturita</th> <th class='tg' style='color: black'>Voto Maturita</th> <th class='tg' style='color: black'>Accetta</th> </tr><?php while ($row = @mysql_fetch_assoc($risultato)) { echo " <tr align='center'> <td class='tg' style='color: black'>" . $row['id_studente'] . "</td> <td class='tg' style='color: black'>" . $row['nome'] . "</td> <td class='tg' style='color: black'>" . $row['cognome'] . "</td> <td class='tg' style='color: black'>" . $row['anno_maturita'] . "</td> <td class='tg' style='color: black'>" . $row['voto_maturita'] . "</td> <td class='tg' style='color: black'>" . "<input type=\"hidden\" name=\"rifiuta\"/><input type=\"checkbox\" name=\"accetta\"/>" . "</td> </tr>"; } ?> </table> </div> <div align='center'> <a href='AreaAmministratore.phtml'>Torna indietro.</a> <input type='submit' value='Prosegui'/> </div> </form> </html> <?php session_start(); include("connetti.php"); if (isset($_POST["accetta"])) { $accetta = 1; } else { $accetta = 0; } if ($accetta) { $cognome = $_POST['cognome']; $nome = $_POST['nome']; $id_studente = $_POST['id_studente']; $query = "UPDATE utenti_studenti SET confermato='1' WHERE nome='$nome' AND cognome='$cognome' AND id_studente='$id_studente'"; $risultato = @mysql_query($query) or die('<p align="center">Errore!</p>' . mysql_error()); echo("<script>alert('La modifica eseguita')</script>"); header("refresh:0;url='AreaAmministratore.phtml'"); } else { echo "<script>alert('Errore');</script>"; header("refresh:0;url='AreaAmministratore.phtml'"); exit(); } ?> Greetings guys, could you help me with those codes above? Cuz I can't understand why it doesn't work... So I have an table with the users that not confirmed. So to confirm them I've made checkbox, so on the other side I have a control if the checkbox is checked so I need to update some values on my database right ? Well it doesn't work.... Link to comment Share on other sites More sharing options...
Don E Posted May 26, 2016 Share Posted May 26, 2016 Are you seeing any errors anywhere? Try and remove @ from @mysql_query so that errors are not suppressed. If the columns confermato and id_studente are of type int, you do need single quotes for the value. Side note, if you're going to use MySQL, it's recommended to use MySQLi instead along with prepared statements. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 26, 2016 Share Posted May 26, 2016 You're giving all of your checkboxes the same name and no values, you have no way to determine which one was checked. You're also checking for $_POST['cognome'], $_POST['nome'], and $_POST['id_studente'] which were not submitted with the form. Link to comment Share on other sites More sharing options...
john_jack Posted May 26, 2016 Share Posted May 26, 2016 (edited) first i suggest you use PDO instead of mysql_ . while ($row = @mysql_fetch_assoc($risultato)) { echo " <tr align='center'> <td class='tg' style='color: black'>" . $row['id_studente'] . "</td> <td class='tg' style='color: black'>" . $row['nome'] . "</td> <td class='tg' style='color: black'>" . $row['cognome'] . "</td> <td class='tg' style='color: black'>" . $row['anno_maturita'] . "</td> <td class='tg' style='color: black'>" . $row['voto_maturita'] . "</td> <td class='tg' style='color: black'>" . "<input type=\"hidden\" name=\"rifiuta\"/><input type=\"checkbox\" name=\"accetta\"/>" . "</td> </tr>"; } you are using a static name for the form input while inside a while loop , so if you have 2 results in database they will be 2 inputs named rifuta , try to ad a $counter that you increment inside the loop and use that on the input (name="rifiuta1" for the first and rifuta2 for the second ) and yu have to verify those $_post on php side . Edited May 27, 2016 by john_jack Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now