Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]UPDATE do bazy danych z formularza tabeli
damiandamian
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 18.11.2016

Ostrzeżenie: (0%)
-----


Elo 420
Chciałbym żeby można było edytować wartości ocen w tabeli wyświetlającej oceny wszystkich uczniów danej klasy .

klasa.php
  1. <table width="100%" align="center" border="1" bordercolor="#d5d5d5" cellpadding="0" cellspacing="0">
  2. <tr>
  3. <?php
  4.  
  5.  
  6. if ($_SESSION['nauczyciel'] = false)
  7. {
  8. header('Location: logout.php');
  9. exit();
  10. }
  11.  
  12.  
  13. echo "<p>Witaj ".$_SESSION['user'].'! [ <a href="logout.php">Wyloguj się!</a> ] </p>';
  14.  
  15.  
  16.  
  17. ini_set("display_errors", 0);
  18. require_once "connect.php";
  19. $polaczenie = mysqli_connect($db_host, $db_user, $db_password, $db_name);
  20. mysqli_query($polaczenie, "SET CHARSET utf8");
  21. mysqli_query($polaczenie, "SET NAMES 'utf8' COLLATE 'utf8_polish_ci'");
  22. mysqli_select_db($polaczenie, $database);
  23.  
  24. $class = $_SESSION['class'] ;
  25. echo $class ;
  26.  
  27. $rezultat = mysqli_query($polaczenie, ("SELECT uczniowie.id, uczniowie.klasa, uczniowie.nr, oceny.id_ucznia, oceny.polski, oceny.matematyka, oceny.niemiecki, oceny.angielski, oceny.wf, oceny.informatyka, oceny.fizyka, oceny.biologia, oceny.fizyka, oceny.biologia, oceny.historia, oceny.religia, oceny.technika, oceny.chemia, oceny.geografia FROM oceny, uczniowie WHERE uczniowie.id = oceny.id_ucznia AND uczniowie.klasa = '$class' ORDER BY uczniowie.nr ASC"));
  28. $ile = mysqli_num_rows($rezultat);
  29.  
  30.  
  31.  
  32.  
  33. if ($ile>=1)
  34. {
  35. echo<<<END
  36. <td width="50" align="center" bgcolor="e5e5e5">Nr</td>
  37. <td width="100" align="center" bgcolor="e5e5e5">Polski</td>
  38. <td width="100" align="center" bgcolor="e5e5e5">Matematyka</td>
  39. <td width="100" align="center" bgcolor="e5e5e5">Angielski</td>
  40. <td width="100" align="center" bgcolor="e5e5e5">Niemiecki</td>
  41. <td width="100" align="center" bgcolor="e5e5e5">WF</td>
  42. <td width="100" align="center" bgcolor="e5e5e5">Informatyka</td>
  43. <td width="100" align="center" bgcolor="e5e5e5">Fizyka</td>
  44. <td width="100" align="center" bgcolor="e5e5e5">Biologia</td>
  45. <td width="100" align="center" bgcolor="e5e5e5">Historia</td>
  46. <td width="100" align="center" bgcolor="e5e5e5">Religia</td>
  47. <td width="100" align="center" bgcolor="e5e5e5">Technika</td>
  48. <td width="100" align="center" bgcolor="e5e5e5">Chemia</td>
  49. <td width="100" align="center" bgcolor="e5e5e5">Geografia</td>
  50.  
  51. </tr><tr >
  52. END;
  53. }
  54.  
  55. for ($i = 1; $i <= $ile; $i++)
  56. {
  57.  
  58. $row = mysqli_fetch_assoc($rezultat);
  59. $a1 = $row['nr'];
  60. $a2 = $row['polski'];
  61. $a3 = $row['matematyka'];
  62. $a4 = $row['angielski'];
  63. $a5 = $row['niemiecki'];
  64. $a6 = $row['wf'];
  65. $a7 = $row['informatyka'];
  66. $a8 = $row['fizyka'];
  67. $a9 = $row['biologia'];
  68. $a10 = $row['historia'];
  69. $a11 = $row['religia'];
  70. $a12 = $row['technika'];
  71. $a13 = $row['chemia'];
  72. $a14 = $row['geografia'];
  73.  
  74.  
  75. echo<<<END
  76. <form action="edytuj.php" name="edytuj" method="post">
  77. <td width="10" align="center">$a1</td>
  78. <td width="100" align="center"><input type="text" name="$a2" value="$a2"></td>
  79. <td width="100" align="center"><input type="text" name="$a3" value="$a3"></td>
  80. <td width="100" align="center"><input type="text" name="$a4" value="$a4"></td>
  81. <td width="100" align="center"><input type="text" name="$a5" value="$a5"></td>
  82. <td width="100" align="center"><input type="text" name="$a6" value="$a6"></td>
  83. <td width="100" align="center"><input type="text" name="$a7" value="$a7"></td>
  84. <td width="100" align="center"><input type="text" name="$a8" value="$a8"></td>
  85. <td width="100" align="center"><input type="text" name="$a9" value="$a9"></td>
  86. <td width="100" align="center"><input type="text" name="$a10" value="$a10"></td>
  87. <td width="100" align="center"><input type="text" name="$a11" value="$a11"></td>
  88. <td width="100" align="center"><input type="text" name="$a12" value="$a12"></td>
  89. <td width="100" align="center"><input type="text" name="$a13" value="$a13"></td>
  90. <td width="100" align="center"><input type="text" name="$a14" value="$a14"></td>
  91. </tr>
  92.  
  93. <tr>
  94. </form>
  95. END;
  96. }
  97. echo '<form action="edytuj.php" name="edytuj" method="post">
  98. <input type="submit" name"edytuj" method="post"></form>' ;
  99.  
  100.  
  101.  
  102.  
  103. $polaczenie->close();
  104.  
  105.  
  106. ?>
  107. </tr></table>




Tabela wyświetla się prawidłowo. Wysyłam wartości do pliku edytuj.php ale to nie działa . Zaznaczam że chciałbym aby można było edytować oceny różnych uczniów z różnych przedmiotów na raz

edytuj.php

  1. <?php
  2.  
  3.  
  4.  
  5.  
  6. ini_set("display_errors",0);
  7. require_once "connect.php";
  8. $polaczenie = mysqli_connect($db_user, $db_password, $db_name, $db_host);
  9. mysqli_select_db($polaczenie, $database); ///połączenie z bazą
  10.  
  11. $a1 = $_POST['$a1'];
  12. $a2 = $_POST['$a2'];
  13. $a3 = $_POST['$a3'];
  14. $a4 = $_POST['$a4'];
  15. $a5 = $_POST['$a5'];
  16. $a6 = $_POST['$a6'];
  17. $a7 = $_POST['$a7'];
  18. $a8 = $_POST['$a8'];
  19. $a9 = $_POST['$a9'];
  20. $a10 = $_POST['$a10'];
  21. $a11 = $_POST['$a11']; ///zmienne z klasa.php
  22. $a12 = $_POST['$a12'];
  23. $a13 = $_POST['$a13'];
  24. $a14 = $_POST['$a14'];
  25.  
  26.  
  27.  
  28.  
  29. $rezultat = mysqli_query($polacznie, ("UPDATE oceny SET oceny.polski = '$a2', oceny.matematyka = '$a3', oceny.angielski = '$a4', oceny.niemiecki = '$a5', oceny.wf = '$a6', oceny.informatyka = '$a7', oceny.fizyka = '$a8', oceny.biologia = '$a9', oceny.historia = '$a10', oceny.religia = '$a11', oceny.technika = '$a12', oceny.chemia = '$a13', oceny.geografia = '$a14' WHERE id_ucznia = $a1 "));
  30.  
  31. $polaczenie->close;
  32. header('Location: klasa.php');
  33.  
  34.  
  35.  
  36.  
  37.  
  38. ?>



budowa bazy danych :

oceny
  1. CREATE TABLE `oceny` (
  2. `id_ucznia` int(11) NOT NULL,
  3. `polski` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  4. `matematyka` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  5. `angielski` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  6. `niemiecki` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  7. `wf` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  8. `informatyka` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  9. `fizyka` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  10. `biologia` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  11. `historia` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  12. `religia` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  13. `technika` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  14. `chemia` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL,
  15. `geografia` varchar(30) COLLATE utf8mb4_polish_ci NOT NULL
  16. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_polish_ci;




uczniowie


  1. CREATE TABLE `uczniowie` (
  2. `id` int(11) NOT NULL,
  3. `user` varchar(30) CHARACTER SET latin1 NOT NULL,
  4. `pass` varchar(30) CHARACTER SET latin1 NOT NULL,
  5. `nr` tinyint(4) NOT NULL,
  6. `klasa` varchar(30) CHARACTER SET latin1 NOT NULL
  7. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_polish_ci;



Zastanwiam się nad użyciem tablicy asocjacyjnej ale nie bardzo wiem jakby miała wyglądać :/

Ten post edytował damiandamian 6.12.2016, 19:23:03
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 18:57