Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db_username = "peoplein"; //Input your database username here
- $db_password = "xxxxxxx"; //Input your database password here
- $db_host = "localhost"; //Input your database host here
- $db_name = "xxxxxxxx"; //Input your database name here
- $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
- try {
- $connection = new PDO("mysql:host={$db_host};dbname={$db_name};charset=utf8", $db_username, $db_password, $options);
- $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $ex) {
- echo "Cannot connect to database.";
- }
- header('Content-Type: text/html; charset=utf-8');
- ?>
- <!doctype html>
- <html>
- <head>
- <title>Login</title>
- </head>
- <body>
- <center>
- <h3>Login</h3>
- <form action="" method="POST">
- Username: <input type="text" name="user">
- Password: <input type="password" name="pass">
- <input type="submit" value="Login" name="submit" />
- </form>
- <?php
- //Grabs the database connection
- require("path to database connection file");
- $user = $_POST["user"];
- $pass = $_POST["pass"];
- $query="SELECT * FROM login WHERE username=:username AND password=:password";
- $params->execute(array(':username' => $user,
- ':password' => $pass));
- try{
- $stmt = $connection->prepare($query);
- $result = $stmt->execute($params);
- }
- catch(PDOException $ex){
- echo ("Failed to run query: " . $ex->getMessage());
- }
- $fetch = $stmt->fetch();
- if($fetch) {
- while($row=mysql_fetch_assoc($query)){
- $usernamefetch=$fetch['username'];
- $passwordfetch=$fetch['password'];
- }
- if($user == $usernamefetch && $pass == $passwordfetch){
- session_start();
- $_SESSION['sess_user']=$user;
- }else{
- echo "Wrong data";
- }
- }
- ?>
- <meta http-equiv='refresh' content="0" url="http://peopleinvestment.ro/filip/admin.php">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment