title: PHP: User Management, Data Access
body: <p>i made a little web application in university and have some problems with data access.</p>
  
  <p>There are 3 user accounts which can log in and all of them can create their own lectures afterwards.</p>
  
  <p>Problem:
  Each teacher should only see the lectures he created and not the ones the other two created. At the moment every teacher sees every lecture. </p>
  
  <p>I don't know which code I should post here, but I am very thankful for any kind of help!</p>
  
  <p>Thanks so much! </p>
  
  <p>Edit: Thanks for your answer. I tried it the last few hours, but I have not idea what to to anymore.</p>
  
  <p>That's my code where I save the lecture into the database. There seems to be a problem with the $_SESSION.</p>
  
  <pre><code>public function save(Vorlesung $vorlesung)
      {
  
          try {
              $stmt = $this-&gt;pdo-&gt;prepare('
                INSERT INTO vorlesung
                  (name, login_dozent)
                VALUES
                  (:name, '$_SESSION[dozent]')
              ');
              $stmt-&gt;bindParam(':name', $vorlesung-&gt;name);
              $stmt-&gt;execute();
          } catch (PDOException $e) {
              echo("Fehler! Bitten wenden Sie sich an den Administrator...&lt;br&gt;" . $e-&gt;getMessage() . "&lt;br&gt;");
              die();
          }
          return $vorlesung;
      }
  </code></pre>
  
  <p>That's my login code:</p>
  
  <pre><code>&lt;?php
  require_once("Mapper/DozentManager.php");
  require_once("Mapper/Dozent.php");
  
  $login = htmlspecialchars($_POST["login"], ENT_QUOTES, "UTF-8");
  $password = htmlspecialchars($_POST["password"], ENT_QUOTES, "UTF-8");
  
  if (!empty($login) &amp;&amp; !empty($password)) {
      $DozentManager = new DozentManager();
      $dozent = $DozentManager-&gt;findByLogin($login, $password);
      if ($dozent==null) {
          header('Location: login.php');
          die();
      } else {
          session_start();
          $_SESSION ['dozent'] = $dozent;
          $_SESSION ['login'] = "1";
          header('Location: index.php');
          die();
      }
  } else {
      echo "Error: Bitte alle Felder ausfüllen!&lt;br/&gt;";
  }
  </code></pre>