Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $username = trim($_POST['username']);
- $password = trim($_POST['password']);
- /* Create a new mysqli object with database connection parameters */
- $mysqli = mysqli_connect('localhost', 'root', '', 'draftdb');
- if(mysqli_connect_errno())
- {
- echo "Connection Failed: " . mysqli_connect_errno();
- exit();
- }
- /* Create a prepared statement */
- if($stmt = $mysqli -> prepare("SELECT Login_ID, Login_PW,
- FROM login
- WHERE Login_ID=? AND Login_PW =?"))
- {
- /* Bind parameters
- s - string, b - boolean, i - int, etc */
- $stmt -> bind_param("ss", $username, $password);
- /* Execute it */
- $stmt -> execute();
- /* Bind results */
- $stmt -> bind_result($username, $password);
- /* Fetch the value */
- if($stmt->fetch() == true)
- {
- $row =$query -> fetch();
- $_SESSION['name'] = $row;
- header("Location:/in.php");
- exit();
- }
- else
- {
- echo 'Invalid Login';
- }
- /* Close statement */
- $stmt -> close();
- }
- /* Close connection */
- $mysqli -> close();
- ?>
- $a = array();
- while ($stmt->fetch()) {
- $a = array('username' => $username, 'password' => $password);
- }
- $_POST['username'];
- $_POST['password'];
- $username;
- $password;
- if($stmt->fetch() == true) { } // equals: if ($stmt->fetch()) { }
- $sql = "SELECT Login_ID, Login_PW,
- FROM login
- WHERE Login_ID=?
- ";
- $stmt = $mysqli->prepare( $sql );
- // Do your thing...
- // Make sure the user is found.
- if ( ! $stmt->rowCount() )
- return false;
- // Retrieve your results as an associative array.
- $user = $stmt->fetch();
- // Check the password.
- if ( ! $_POST['password'] == $user['Login_PW'] ) )
- return false;
- $_SESSION['name'] = $user['Login_ID'];
- header("Location:/in.php");
- exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement