UPDATE danych do bazy MySql

0

Mam problem z uaktualnieniem danych z bazy MySql. Napisałem skrypt który pobiera dane z bazy mysql ale ich nie uaktualnia:

<?php
  include '../includes/common.inc.php';
  include '../includes/klasy.inc.php';
  include '../includes/students.inc.php';
  include '../includes/plan.inc.php';
  include '../includes/przedmioty.inc.php';
 
  require_group(_TEACHER_GROUP);
 
  extract($_POST);
  page_header();
  page_menu();
 
$classid=$_REQUEST['classid'];
$przedmiotid=$_REQUEST['przedmiotid']; 
 
  if (!isset($_REQUEST['classid'])) {
      $classid = intval($_REQUEST['classid']);
	  $przedmiotid = intval($_REQUEST['przedmiotid']);
      $classinfo = classGetClassById($classid);
	  $przedmiotinfo = przedmiotGetPrzedmiotById(intval($przedmiotid));
  } else {
      $classid = intval($_REQUEST['classid']);
      $classinfo = classGetClassById($classid);
	  $przedmiotid = intval($_REQUEST['przedmiotid']);
	  $przedmiotinfo = przedmiotGetPrzedmiotById(intval($przedmiotid));
  }
 
// Wstawinie ocen ------------------------------------------------------------------------
?>
<div id="content">
<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>
 
<?php if ($success) echo "<strong class=\"success\">$success</strong>"; ?>
 
<div style="clear: both;"></div>
 
<?php
 $studentlist = classGetStudentsById($classid);
 
 if (empty($studentlist)) {
?>
 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>.
<?php
 } else {
?>
 
<form method="post" action="change.php">
<table cellpadding="5" class="classlist">
<tr><th rowspan="2">ID</th><th rowspan="2">Nazwisko</th><th rowspan="2">Imię</th><th colspan="11">Oceny</th></tr>
  <tr>
<?php 
  for($j=0; $j < 11; $j++) {
   echo "<th>";
   $n=$j+1;  
   echo $n.'</th>';
    }
    echo '</tr>';
	 $i = 0;
	 foreach ($studentlist as $student)
	 {
	   $i++;
	   $studentinfo = studentGetStudentById(intval($student['studentid']));
	   if ($i % 2)
	    echo '<tr class="even">';
	   else
	    echo '<tr class="odd">';
	   echo '<td>'. $student['studentid'] .'</td>';
	   echo '<td>' . $studentinfo['lastname'] . '</td>';
   	   echo '<td>' . $studentinfo['firstname'] . '</td>';
 
$query='SELECT marks FROM '._MARKS_DB_TABLE.' WHERE `studentid`='.$student['studentid'].' AND przedmiotid='.$przedmiotid.' LIMIT 1';
$result = @mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
 
$marks = explode("|", $row['marks']);
 
for($j=0; $j < 11; $j++) {?>
<td><input type="text" name="marks[]" maxlength="2" size="3" class="inputbox" value="<?php if(isset($marks[$j])) echo $marks[$j];?>" ></td>
<?  }
	echo '</tr>';
	   echo "\n";
	   }
	   echo '</table>';
?>
<input type="hidden" name="przedmiotid" value="<?=$przedmiotid?>" />
<input type="hidden" name="classid" value="<?=$classid?>" />
<input type="hidden" name="studentid" value="<?=$studentid?>" />
<input type="hidden" name="marks" value="<?=$marks?>" />
<input type="submit" value="Zapisz" />
</form>
<?php  }   ?>
</div> <!-- content -->
 
<?php
  page_footer();
echo "<pre>".print_r($_POST, true)."</pre>"; 
?>

oraz plik change.php:

<?php
 
  include '../includes/common.inc.php';
  include '../includes/klasy.inc.php';
  include '../includes/students.inc.php';
 
  require_group(_TEACHER_GROUP);
 
  if (isset($_GET['success'])) $success = success('Oceny', $_GET['success']);
 
  if (!isset($_POST['classid'], $_POST['przedmiotid'], $_POST['marks'])) { header('Location: /oceny/'); 	exit; }
 
$classid = intval($_POST['classid']);
$przedmiotid = intval($_POST['przedmiotid']);
$marks = intval($_POST['marks']);
 
if (isset($classid)) { 
$studentlist = classGetStudentsById($classid);
foreach($studentlist as $student) {
 
$query_update = "UPDATE `intra_marks` SET `marks` = '".implode('|',$marks)."' WHERE `studentid` = '".$student['studentid']."' AND `przedmiotid` = '".$przedmiotid."' ";
$result_update = @mysql_query($query_update) or die(mysql_error());
}
}
  header('Location: /oceny/index.php?success=2');
  exit;
  echo "<pre>".print_r($_POST, true)."</pre>"; 
?>

Jeżeli ktoś wie gdzie popełniłem błąd to bardzo proszę o pomoc.

0

Wstaw sobie przed zapytaniem

echo implode('|',$marks);

to będziesz wiedział co się dzieje.

O sposobie przechowywania ocen w bazie danych się nie wypowiem. Życzę powodzenia w walce ze swoim kodem :)

1 użytkowników online, w tym zalogowanych: 0, gości: 1