Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function dbconnect($host, $user, $password, $db)
- {
- $host = "localhost";
- $user = "web";
- $password = "web";
- $db = "web";
- global $link;
- if(!($link= new mysqli($host, $user, $password, $db)))
- {
- echo 'Mysql error: ' .$link->connect_error;
- exit();
- }
- print_r($link->host_info);
- }
- function user_check($login, $password)
- {
- $login = $_POST['email'];
- $password = $_POST['password'];
- $login_check_query = "SELECT * FROM users WHERE email=?";
- $password_check_query = "SELECT * FROM users WHERE password=?";
- $stmt = $link->prepare($login_check_query);
- $stmt->bind_param('s',$login);
- $stmt->execute();
- if(($stmt->affected_rows) > 0)
- {
- $stmt->close();
- $stmt = $link->prepare($password_check_query);
- $stmt->bind_param('s',$password);
- $stmt->execute();
- if(($stmt->affected_rows) > 0)
- {
- $stmt->close();
- return true;
- echo 'true';
- }
- else
- {
- $stmt->close();
- return false;
- echo 'false';
- }
- }
- }
- function registration($login, $password)
- {
- $login = $_POST['email'];
- $password = $_POST['password'];
- $user_insert_query = "INSERT INTO users (password, email) VALUES(?,?)";
- if(user_check($login,$password))
- {
- $stmt = $link->prepare($user_insert_query);
- $stmt->bind_param('ss',$password,$login);
- $stmt->execute();
- $stmt->close();
- }
- else
- {
- echo 'Username busy';
- }
- }
- dbconnect();
- if(isset($_POST['email']) && isset($_POST['password']))
- {
- $login = $_POST['email'];
- $password = $_POST['password'];
- user_check($login, $password);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Ololo</title>
- <meta charset="utf-8" />
- </head>
- <body>
- <form action="index.php" method="POST">
- Email: <input type="text" name="email" /><br />
- Password: <input type="password" name="password" /><br />
- <input type="submit" value="GO"/>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement