I had made a previous post regarding this and have been working on this issue for quite a while.
I am unable to pass data from page1 to page2. I have looked at various tutorials online but have not been able to get the desired result.
I am new to both MongoDB and PHP. If someone could explain how I can query data from mongoDB.
Below I am posting the code for both pages
//LOGIN PAGE <? PHP session_start(); ?> <html> <head> <title> Movie Database </title> </head> <?PHP try { // open connection to MongoDB server $conn = new Mongo('localhost'); // access database $db = $conn->test; // access collection $collection = $db->items; // execute query $cursor = $collection->find(); foreach ($cursor as $obj) { $correct = $obj['username']; } // disconnect from server $conn->close(); } catch (MongoConnectionException $e) { die('Error connecting to MongoDB server'); } catch (MongoException $e) { die('Error: ' . $e->getMessage()); } ?> <body> <br> <center> <h1> Welcome to Login Page </h1> <br> <br> <br> <form action="page.php" METHOD="POST"> <label>Username :</label> <input type="text" Name="username"> <br> <label>Password :</label> <input type="password" Name="password"> <br> <br> <input type="submit" value="Login"> <br> </center> </FORM> </body> </html> Second Page starts from here
//PAGE 2 <?PHP session_start(); //$db = $conn->test; //echo 'Username: ' . $_POST['username'] . '<br>'; //echo 'Password: ' . $_POST['password'] . '<br>'; $userName = $_POST['username']; $userPass = $_POST['password']; $collection = $db->items; $userN = array('username'=>$userName); $userP = array('password'=>$userPass); $cursor = $collection->find(array($userN,$userP)); foreach ($cursor as $obj) { $foundUserN = $obj['username']; $foundUserP = $obj['password']; if($obj['username'] == $userName && $obj['password'] == $userPass){ echo '<h1>FOUND</h1>'; } else{ echo 'not found'; } } $conn->close(); try { $conn = new Mongo('localhost'); $db = $conn->test; $conn->close(); } catch (MongoConnectionException $e) { die('Error connecting to MongoDB server'); } catch (MongoException $e) { die('Error: ' . $e->getMessage()); } ?>