Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Funkcja foreach i przekazywane danych do mysql, Przekazywanie danych do bazy
przemokrosno
post
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 30.09.2008
Skąd: Krosno

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


Witam
Napisałem skrypt który zwraca zwraca sukces ale mimo wszystko nic się nie wykonuje tzn nie dodaje rekordów do bazy danych. Jeśli dodam je ręcznie to wyświetla prawidłowo. Jeśli zamienię funkcję INSERT na DELETE to również działa bez problemu
Męczy mnie to już trzeci dzień i nie mogę znaleźć żadnego błędu. Dlatego bardzo proszę o pomoc Jeśli ktoś potrafi wskazać mi błąd to będę bardzo wdzięczny.
  •  if (!isset($_POST['class'], $_POST['toyear'], $_POST['tomonth'], $_POST['today'])) {
  •      if (!isset($_GET['id']))  
  •     exit;
  •  }
  •  
  •  page_header();
  •  page_menu();
  •  
  •  if (!isset($_GET['id'])) {
  •  
  •      $absentdate = $_POST['toyear'] . '-' . $_POST['tomonth'] . '-' . $_POST['today'];
  •      
  •      $classid = intval($_POST['class']);
  •      $classinfo = classGetClassById($classid);
  •  } else {
  •      $absentdate = date('Y-m-d');
  •      $classid = intval($_GET['id']);
  •      $classinfo = classGetClassById($classid);
  •  }
  •  
  •  $confquery = 'SELECT * FROM `CONFIG_DB_TABLE` WHERE `id`=1 ';
  •  $confresult = mysql_query($confquery) or die(mysql_error());
  •  $confrow = mysql_fetch_array($confresult);
  •  $max=$confrow['lessonmax'];
  •  
  • // Wstawinie nieobecności ------------------------------------------------------------------------
  •  if ($_POST['todo'] == 'Wstaw') {
  • ?>
  • <div id="content">
  • <h2>Wstawianie nieobecności w klasie <?=$classinfo['name']?>, <?php echo $absentdate; ?></h2>
  • <div id="breadcrumb"><a href="<?=$conf_settings['site_url']?>">Strona główna</a> -> <a href="/frekwencja/">Frekwencja</a> -> <em>Wstawianie nieobecności</em></div>
  •  
  • <?php if ($success) echo "<strong class="success">$success</strong>"; ?>
  •  
  • <div id="subnav">
  • <ul>
  •  <li>
  •   <form method="post" action="do.php" class="search">
  •    <label for="toyear">
  •     <img src="/images/options/search.png"/>
  •     &nbsp;Przejdź do:
  •    </label>
  •   <?php dateboxes(true, false); ?>
  •   <label for="class">
  •    Klasy:
  •   </label>
  •   <?php classSelectBox(); ?>
  •    <input type="submit" name="submit" value="Przejdź" />
  •   </form>
  •  </li>
  • </ul>
  • </div>
  • <div style="clear: both;"></div>
  •  
  • <p>Umieść znacznik obok każdego nieobecnego ucznia.</p>
  •  
  • <?php
  • $studentlist = classGetStudentsById($classid);
  •  
  • if (empty($studentlist)) {
  • ?>
  • W tej klasie nie ma wpisanych uczniów.  Aby zarządzać frekwencją, musisz <a href="/klasy/dodajstudent.php">dodać uczniów do tej klasy</a>.
  • <?php
  • } else {
  • ?>
  •  
  • <form method="post" action="wstaw.php">
  • <table cellpadding="5" class="classlist">
  • <tr><th rowspan="2">ID ucznia</th><th rowspan="2">Imię</th><th rowspan="2">Nazwisko</th><th rowspan="2">Nieobecny?</th><th colspan="<?=$max?>">Lekcje</th></tr>
  •  <tr>  <?php
  •  for($j=0; $j < $max; $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['firstname'] . '</td>';
  •      echo '<td>' . $studentinfo['lastname'] . '</td>';
  •      
  •      $absent = getStudentAttendance($absentdate,  $classid, intval($student['studentid']));
  •      $lesson = explode('|',$_POST['lesson']);
  •      if ($absent == true) {
  •            $absvalue = 'checked="checked" ';
  •      }
  •      
  •      echo '<td><input type="checkbox" name="student['.$student['studentid'].']" '.$absvalue.'/></td>';
  •      
  •   for($j=0; $j < $max; $j++) {
  •      if ($lesson[$j] == 1){
  •   $lesson_value[$j] = 'checked="checked"';
  •   }  ?>
  •    
  •   <td><input type="checkbox" name="<?php if(isset($lesson[$j])) echo $lesson[$j];?>" <?php echo $lesson_value[$j];?> ></td>
  •    <?php  
  •   if ($lesson[$j] == true){
  •   $lesson[$j] = 1;
  •   } else {
  •   $lesson[$j] = 0;
  •   }
  •   }
  •      echo '</tr>';
  •      echo "n";
  •    }
  •    echo '</table>';
  • }
  • ?>
  • <input type="hidden" name="absentdate" value="<?=$absentdate?>" />
  • <input type="hidden" name="classid" value="<?=$classid?>" />
  • <input type="hidden" name="classid" value="<?=$studentid?>" />
  • <input type="hidden" name="lesson" value="<?=$lesson = implode('|',$_POST['lesson'])?>" />
  • <input type="submit" name="todo" value="Wstaw" />
  •  
  • <?php
  •  // Koniec wstawiania nieobecności -------------------------------------------------------------------
  •  page_footer();
  • ?>

    [/list]
  •  define('_ATTENDANCE_DB_TABLE', $conf_settings['db_tblprefix'] . 'attendance');
  •  
  •  if (!isset($_POST['class'], $_POST['toyear'], $_POST['tomonth'], $_POST['today'])) {
  •      if (!isset($_GET['id']))  
  •     exit;
  •  }
  •  
  •  page_header();
  •  page_menu();
  •  
  •  if (!isset($_GET['id'])) {
  •  
  •      $absentdate = $_POST['toyear'] . '-' . $_POST['tomonth'] . '-' . $_POST['today'];
  •      
  •      $classid = intval($_POST['class']);
  •      $classinfo = classGetClassById($classid);
  •  } else {
  •      $absentdate = date('Y-m-d');
  •      $classid = intval($_GET['id']);
  •      $classinfo = classGetClassById($classid);
  •  }
  •  
  •  $confquery = 'SELECT * FROM `CONFIG_DB_TABLE` WHERE `id`=1 ';
  •  $confresult = mysql_query($confquery) or die(mysql_error());
  •  $confrow = mysql_fetch_array($confresult);
  •  $max=$confrow['lessonmax'];
  •  
  • // Wstawinie nieobecności ------------------------------------------------------------------------
  •  if ($_POST['todo'] == 'Wstaw') {
  • ?>
  • <div id="content">
  • <h2>Wstawianie nieobecności w klasie <?=$classinfo['name']?>, <?php echo $absentdate; ?></h2>
  • <div id="breadcrumb"><a href="<?=$conf_settings['site_url']?>">Strona główna</a> -> <a href="/frekwencja/">Frekwencja</a> -> <em>Wstawianie nieobecności</em></div>
  •  
  • <?php if ($success) echo "<strong class="success">$success</strong>"; ?>
  •  
  • <div id="subnav">
  • <ul>
  •  <li>
  •   <form method="post" action="do.php" class="search">
  •    <label for="toyear">
  •     <img src="/images/options/search.png"/>
  •     &nbsp;Przejdź do:
  •    </label>
  •   <?php dateboxes(true, false); ?>
  •   <label for="class">
  •    Klasy:
  •   </label>
  •   <?php classSelectBox(); ?>
  •    <input type="submit" name="submit" value="Przejdź" />
  •   </form>
  •  </li>
  • </ul>
  • </div>
  • <div style="clear: both;"></div>
  •  
  • <p>Umieść znacznik obok każdego nieobecnego ucznia.</p>
  •  
  • <?php
  • $studentlist = classGetStudentsById($classid);
  •  
  • if (empty($studentlist)) {
  • ?>
  • W tej klasie nie ma wpisanych uczniów.  Aby zarządzać frekwencją, musisz <a href="/klasy/dodajstudent.php">dodać uczniów do tej klasy</a>.
  • <?php
  • } else {
  • ?>
  •  
  • <form method="post" action="wstaw.php">
  • <table cellpadding="5" class="classlist">
  • <tr><th rowspan="2">ID ucznia</th><th rowspan="2">Imię</th><th rowspan="2">Nazwisko</th><th rowspan="2">Nieobecny?</th><th colspan="<?=$max?>">Lekcje</th></tr>
  •  <tr>  <?php
  •  for($j=0; $j < $max; $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['firstname'] . '</td>';
  •      echo '<td>' . $studentinfo['lastname'] . '</td>';
  •      
  •      $absent = getStudentAttendance($absentdate,  $classid, intval($student['studentid']));
  •      $lesson = explode('|',$_POST['lesson']);
  •      if ($absent == true) {
  •            $absvalue = 'checked="checked" ';
  •      }
  •      
  •      echo '<td><input type="checkbox" name="student['.$student['studentid'].']" '.$absvalue.'/></td>';
  •      
  •   for($j=0; $j < $max; $j++) {
  •      if ($lesson[$j] == 1){
  •   $lesson_value[$j] = 'checked="checked"';
  •   }  ?>
  •    
  •   <td><input type="checkbox" name="<?php if(isset($lesson[$j])) echo $lesson[$j];?>" <?php echo $lesson_value[$j];?> ></td>
  •    <?php  
  •   if ($lesson[$j] == true){
  •   $lesson[$j] = 1;
  •   } else {
  •   $lesson[$j] = 0;
  •   }
  •   }
  •      echo '</tr>';
  •      echo "n";
  •    }
  •    echo '</table>';
  • }
  • ?>
  • <input type="hidden" name="absentdate" value="<?=$absentdate?>" />
  • <input type="hidden" name="classid" value="<?=$classid?>" />
  • <input type="hidden" name="classid" value="<?=$studentid?>" />
  • <input type="hidden" name="lesson" value="<?=$lesson = implode('|',$_POST['lesson'])?>" />
  • <input type="submit" name="todo" value="Wstaw" />
  •  
  • <?php
  •  // Koniec wstawiania nieobecności -------------------------------------------------------------------
  •  page_footer();
  • ?>

    [/list]
    [PHP] );
  •  if (!isset($_POST['classid'], $_POST['absentdate'])) {
  •     header('Location: /frekwencja/');
  •     exit;
  •  }
  •  
  •  $date = $_POST['absentdate'];
  •  $classid = intval($_POST['classid']);
  •  
  •  if (isset($_POST['student'])) {
  •  
  •     foreach ($student as $studentid => $status)
  •     {
  •   $query = 'INSERT INTO `intra_attendance` (`classid`, `studentid`, `date_absent`) VALUES ('.$classid.', '.$studentid.', '.$date.');';
  •   $result = @mysql_query($query) or die(mysql_error());
  •   return mysql_insert_id();
  •     }
  •  
  •  }
  •  
  •  header('Location: /frekwencja/index.php?success=1');
  •  exit;
  • ?>

    [/list]
  •  if (!isset($_POST['classid'], $_POST['absentdate'])) {
  •     header('Location: /frekwencja/');
  •     exit;
  •  }
  •  
  •  $date = $_POST['absentdate'];
  •  $classid = intval($_POST['classid']);
  •  
  •  if (isset($_POST['student'])) {
  •  
  •     foreach ($student as $studentid => $status)
  •     {
  •   $query = 'INSERT INTO `intra_attendance` (`classid`, `studentid`, `date_absent`) VALUES ('.$classid.', '.$studentid.', '.$date.');';
  •   $result = @mysql_query($query) or die(mysql_error());
  •   return mysql_insert_id();
  •     }
  •  
  •  }
  •  
  •  header('Location: /frekwencja/index.php?success=1');
  •  exit;
  • ?>

    [/list]
    [PHP] Go to the top of the page
  • +Quote Post

    Posty w temacie


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

     



    RSS Aktualny czas: 27.08.2025 - 12:44