rocks Posted April 19, 2021 at 07:16 PM Report Share #622040 Posted April 19, 2021 at 07:16 PM Boas, Mais uma ajudinha numa aplicação web que estou a deconvolver como alguns ja sabem (Sorry por ser tao chato, Depois faço agradecimentos ). Estou a mostrar as notas dum aluno atreves de um loop a minha questão é como é que depois gravo as alterações na BD ? https://ibb.co/g7wN2Pn Obrigado $sql = "select * FROM cadeiras"; $result = $connect->query($sql); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $sql1 = "SELECT * from alunos where ID = '$id'"; $result1 = $connect->query($sql1); $row1 = $result1->fetch_assoc(); echo "<form id=form_955 method=post action=edit_rec.php><table border=0 width=98% align=center> <table> <tr> <td style=font:bold width=450px >Nome</td> <td style=font:bold width=450px >".$row1['Nome_Completo']."</td> </tr> <tr> <td style=font:bold width=450px >Num</td> <td style=font:bold width=450px >".$row1['NUM_Aluno']."</td> </tr> <tr>"; while($row = mysqli_fetch_array($result)){ echo" <td style=font:bold width=450px >".$row['Nome_PT']."</td>"; $test = $row['ID']; $sql5 = "SELECT notas.Nota from notas, alunos, cadeiras where notas.ID_aluno = alunos.ID and notas.ID_Cadeira = cadeiras.ID and notas.ID_aluno = '$id' and notas.ID_Cadeira = '$test'"; $result5 = $connect->query($sql5); $row5 = $result5->fetch_assoc(); $notas = $row5['Nota']; if ($row5['Nota'] == "" || $row5['Nota'] == '' || $row5['Nota'] = null) { echo " <td><input id='notas' name='notas' type='text' value='XX'></td> "; } else { echo " <td><input id='notas' name='notas' type='text' value=".$notas."></td> "; } $sql = "UPDATE notas SET Nota='".$_POST['Nome_PT']."', Nome_ENG='".$_POST["Nome_ENG"] . "', Sigla='".$_POST["Sigla"] . "' WHERE ID='$id'"; $result1 = $connect->query($sql1); $row1 = $result1->fetch_assoc(); echo" <tr></tr><tr></tr><tr></tr><tr></tr> </tr> "; } echo "</table>"; Link to comment Share on other sites More sharing options...
M6 Posted April 20, 2021 at 12:33 PM Report Share #622048 Posted April 20, 2021 at 12:33 PM Usas um comando insert ou update para gravar. Obténs os valores da variável $_POST. Vê a documentação do PHP para mais informação. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
rocks Posted April 20, 2021 at 12:51 PM Author Report Share #622049 Posted April 20, 2021 at 12:51 PM 16 minutos atrás, M6 disse: Usas um comando insert ou update para gravar. Obténs os valores da variável $_POST. Vê a documentação do PHP para mais informação. Certo, mas o meu problema é a variável vai ser o nome da textbox neste caso notas. Mas como aquilo é gerado num loop devo ter que criar um array e passar por la nao ? Link to comment Share on other sites More sharing options...
M6 Posted April 20, 2021 at 03:49 PM Report Share #622052 Posted April 20, 2021 at 03:49 PM Crias um Id único a que juntas ao nome/id de cada textbox, permitindo-te identificar cada item sem qualquer problema. Por exemplo, se é um update, podes usar o o id da base de dados, gerando uma textbox "nome23" para o nome do registo 23. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
rocks Posted April 20, 2021 at 07:24 PM Author Report Share #622056 Posted April 20, 2021 at 07:24 PM (edited) 4 horas atrás, M6 disse: Crias um Id único a que juntas ao nome/id de cada textbox, permitindo-te identificar cada item sem qualquer problema. Por exemplo, se é um update, podes usar o o id da base de dados, gerando uma textbox "nome23" para o nome do registo 23. Tinha de fazer algo assim né <td><input id='notas' name='notas[$test]' type='text' value=".$notas."></td> E ir buscar com $array = $_POST['notas']; e usar como array $max = max(array_keys($array)); echo $max; echo '<br>'; for ($i = 0; $i <= $max; $i++) { if (array_key_exists($i,$array)) { echo $i; echo $array[$i]; echo '<br>'; } } Edited April 20, 2021 at 07:51 PM by rocks 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