title: MongoDB and PHP simple login
body: <p>I am new to mongoDb and PHP. 
  I am trying to create a simple login page which will take the user input from the text fields and look in the database if the record exists. </p>
  
  <p>For now I am able to pass hard coded values which redirects me to a new page but I am unable to query the database. </p>
  
  <p>If someone can guide me in the rite direction. I have looked at various tutorials online but have not been able to get what I need.</p>
  
  <pre><code>&lt;? PHP      
  session_start();
  ?&gt;
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt; Movie Database &lt;/title&gt;
  &lt;/head&gt;
  
  &lt;?PHP
  
  $_SESSION["loggedInUser"] = $username;
  
  
      try {
          // open connection to MongoDB server
          $conn = new Mongo('localhost');
  
          // access database
          $db = $conn-&gt;test;
  
          // access collection
          $collection = $db-&gt;items;
  
  
          $userName = $_POST['username'];
          $userPass = $_POST['userPassword'];
  
  
          $user = $db-&gt;$collection-&gt;findOne(array('username'=&gt; 'user1', 'password'=&gt; 'pass1'));
  
          foreach ($user as $obj) {
              echo 'Username' . $obj['username'];
              echo 'password: ' . $obj['password'];
              if($userName == 'user1' &amp;&amp; $userPass == 'pass1'){
                  echo 'found'            
              }
              else{
                  echo 'not found'            
              }
  
          }
  
          // disconnect from server
          $conn-&gt;close();
  
      } catch (MongoConnectionException $e) {
          die('Error connecting to MongoDB server');
      } catch (MongoException $e) {
          die('Error: ' . $e-&gt;getMessage());
      }
  
  $_SESSION["loggedInUser"] = $correct;
  
  ?&gt;
  
  &lt;body&gt;
  &lt;br&gt;
  &lt;center&gt;&lt;h1&gt; Welcome to CS348 Login Page &lt;/h1&gt;&lt;/center&gt;
  &lt;br&gt;
  &lt;form action="page2.php" METHOD="POST"&gt;
  &lt;label&gt;Username :&lt;/label&gt;
  &lt;input type="text" Name="username"&gt;
  &lt;br&gt;
  &lt;label&gt;Password :&lt;/label&gt;
  &lt;input type="password" Name="userPassword"&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;input type="submit" value="Login"&gt;
  &lt;br&gt;
  &lt;/FORM&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I am not sure how to take the userinput from the text boxes and query the database.</p>
  
  <p>Thank you for the help</p>