Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Uaktualnienie danych do bazy MySql
Forum PHP.pl > Forum > PHP
przemokrosno
Mam problem z uaktualnieniem danych z bazy MySql. Napisałem skrypt który pobiera dane z bazy mysql ale ich nie uaktualnia:

  1. <?php
  2. include '../includes/common.inc.php';
  3. include '../includes/klasy.inc.php';
  4. include '../includes/students.inc.php';
  5. include '../includes/plan.inc.php';
  6. include '../includes/przedmioty.inc.php';
  7.  
  8. require_group(_TEACHER_GROUP);
  9.  
  10. extract($_POST);
  11. page_header();
  12. page_menu();
  13.  
  14. $classid=$_REQUEST['classid'];
  15. $przedmiotid=$_REQUEST['przedmiotid'];
  16.  
  17. if (!isset($_REQUEST['classid'])) {
  18. $classid = intval($_REQUEST['classid']);
  19. $przedmiotid = intval($_REQUEST['przedmiotid']);
  20. $classinfo = classGetClassById($classid);
  21. $przedmiotinfo = przedmiotGetPrzedmiotById(intval($przedmiotid));
  22. } else {
  23. $classid = intval($_REQUEST['classid']);
  24. $classinfo = classGetClassById($classid);
  25. $przedmiotid = intval($_REQUEST['przedmiotid']);
  26. $przedmiotinfo = przedmiotGetPrzedmiotById(intval($przedmiotid));
  27. }
  28.  
  29. // Wstawinie ocen ------------------------------------------------------------------------
  30. ?>
  31. <div id="content">
  32. <h2>Edycja ocen klasy <?=$classinfo['name']?>, z przedmiotu <?php echo $przedmiotinfo['lessonname']; ?></h2><div id="breadcrumb"><a href="<?=$conf_settings['site_url']?>">Strona główna</a> -> <a href="/oceny/">Oceny</a> -> <em>Edycja ocen</em></div>
  33.  
  34. <?php if ($success) echo "<strong class=\"success\">$success</strong>"; ?>
  35.  
  36. <div style="clear: both;"></div>
  37.  
  38. <?php
  39. $studentlist = classGetStudentsById($classid);
  40.  
  41. if (empty($studentlist)) {
  42. ?>
  43. Aktualnie nie ma uczniów w tej klasie. Aby zarządzać ocenami musisz <a href="/klasy/addstudent.php">dodać uczniów do tej klasy</a>.
  44. <?php
  45. } else {
  46. ?>
  47.  
  48. <form method="post" action="change.php">
  49. <table cellpadding="5" class="classlist">
  50. <tr><th rowspan="2">ID</th><th rowspan="2">Nazwisko</th><th rowspan="2">Imię</th><th colspan="11">Oceny</th></tr>
  51. <tr>
  52. <?php
  53. for($j=0; $j < 11; $j++) {
  54. echo "<th>";
  55. $n=$j+1;
  56. echo $n.'</th>';
  57. }
  58. echo '</tr>';
  59. $i = 0;
  60. foreach ($studentlist as $student)
  61. {
  62. $i++;
  63. $studentinfo = studentGetStudentById(intval($student['studentid']));
  64. if ($i % 2)
  65. echo '<tr class="even">';
  66. else
  67. echo '<tr class="odd">';
  68. echo '<td>'. $student['studentid'] .'</td>';
  69. echo '<td>' . $studentinfo['lastname'] . '</td>';
  70. echo '<td>' . $studentinfo['firstname'] . '</td>';
  71.  
  72. $query='SELECT marks FROM '._MARKS_DB_TABLE.' WHERE `studentid`='.$student['studentid'].' AND przedmiotid='.$przedmiotid.' LIMIT 1';
  73. $result = @mysql_query($query) or die(mysql_error());
  74. $row = mysql_fetch_array($result);
  75. var_dump($row);
  76.  
  77. $marks = explode("|", $row['marks']);
  78.  
  79. for($j=0; $j < 11; $j++) {?>
  80. <td><input type="text" name="marks[]" maxlength="2" size="3" class="inputbox" value="<?php if(isset($marks[$j])) echo $marks[$j];?>" ></td>
  81. <? }
  82. echo '</tr>';
  83. echo "\n";
  84. }
  85. echo '</table>';
  86. ?>
  87. <input type="hidden" name="przedmiotid" value="<?=$przedmiotid?>" />
  88. <input type="hidden" name="classid" value="<?=$classid?>" />
  89. <input type="hidden" name="studentid" value="<?=$studentid?>" />
  90. <input type="hidden" name="marks" value="<?=$marks?>" />
  91. <input type="submit" value="Zapisz" />
  92. </form>
  93. <?php } ?>
  94. </div> <!-- content -->
  95.  
  96. <?php
  97. page_footer();
  98. echo "<pre>".print_r($_POST, true)."</pre>";
  99. ?>

oraz plik change.php:
  1. <?php
  2.  
  3. ini_set('display_errors', 1);
  4.  
  5. include '../includes/common.inc.php';
  6. include '../includes/klasy.inc.php';
  7. include '../includes/students.inc.php';
  8.  
  9. require_group(_TEACHER_GROUP);
  10.  
  11. if (isset($_GET['success'])) $success = success('Oceny', $_GET['success']);
  12.  
  13. if (!isset($_POST['classid'], $_POST['przedmiotid'], $_POST['marks'])) { header('Location: /oceny/'); exit; }
  14.  
  15. $classid = intval($_POST['classid']);
  16. $przedmiotid = intval($_POST['przedmiotid']);
  17. $marks = intval($_POST['marks']);
  18.  
  19. if (isset($classid)) {
  20. $studentlist = classGetStudentsById($classid);
  21. foreach($studentlist as $student) {
  22.  
  23. $query_update = "UPDATE `intra_marks` SET `marks` = '".implode('|',$marks)."' WHERE `studentid` = '".$student['studentid']."' AND `przedmiotid` = '".$przedmiotid."' ";
  24. $result_update = @mysql_query($query_update) or die(mysql_error());
  25. }
  26. }
  27. header('Location: /oceny/index.php?success=2');
  28. echo "<pre>".print_r($_POST, true)."</pre>";
  29. ?>

Jeżeli ktoś wie gdzie popełniłem błąd to bardzo proszę o pomoc.
Fifi209
  1. $marks = intval($_POST['marks']);


  1. "UPDATE `intra_marks` SET `marks` = '".implode('|',$marks)."' WHERE `studentid` = '".$student['studentid']."' AND `przedmiotid` = '".$przedmiotid."' ";


Przyjrzyj się, co robi ten implode ?
przemokrosno
Implode łączy wyrażenia przesłane jako marks w jeden ciąg i rozdziela poszczególne znakiem | questionmark.gif
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.