Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- dbconnection.php -->
- <?php
- $dbname = 'loggin';
- $hostname = 'localhost';
- $username = 'root';
- $password = '';
- $options = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'");
- try {
- $dbConn = new PDO("mysql:host=$hostname;dbname=$dbname;", $username,
- $password, $options);
- $dbConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- /*** echo a message saying we have connected ***/
- echo 'Connected to database.<br />';
- }
- catch(PDOException $e){
- // For debug purpose, shows all connection details
- echo 'Connection failed: '.$e->getMessage()."<br />";
- // Hide connection details.
- //echo 'Could not connect to database.<br />');
- }
- --------------------
- <!--createTable.php-->
- <?php
- include('databaseConnection.php');
- try{
- $sql = "CREATE TABLE Users(
- userID INT(6) AUTO_INCREMENT PRIMARY KEY,
- userName VARCHAR(30) NOT NULL,
- email VARCHAR(30) NOT NULL,
- password VARCHAR(255) NOT NULL
- )";
- $dbConn->exec($sql);
- echo "Table created succesfully!";
- }
- catch(PDOexeption $e){
- echo $sql. "<br>". $e->getMessage();
- }
- $dbConn = null;
- ?>
- -------------
- <!--registerNewUser.php-->
- <!DOCTYPE html>
- <html>
- <head>
- <title>AddUser</title>
- </head>
- <body>
- <form method="POST" action="">
- <input type="text" name="username" placeholder="username">
- <input type="text" name="email" placeholder="Email">
- <input type="password" name="password" placeholder="Password">
- <input type="submit" name="send">
- </form>
- <?php
- include('databaseConnection.php');
- if (isset($_POST['send']))
- {
- $username = $_POST['username'];
- $email = $_POST['email'];
- $password = $_POST['password'];
- function cryptFu($username, $email, $password, $dbConn)
- {
- $md5crypt = md5($username);
- $cryptusername = crypt($username, "!!!". $md5crypt);
- $cryptEmail = crypt($email, "!!!". $md5crypt);
- $cryptPassword = crypt($password, "!!!". $md5crypt);
- addDb($cryptusername, $cryptEmail, $cryptPassword, $dbConn);
- echo"1";
- }
- function addDb($username, $email, $password, $dbConn)
- {
- echo"2";
- try{
- $sql = "INSERT INTO users (username, email, password) VALUES('$username', '$email', '$password')";
- $dbConn->exec($sql);
- }
- catch(PDOException $e){
- echo $sql . "<br>" . $e->getMessage();
- }
- }
- cryptFu($username, $email, $password , $dbConn);
- }
- ?>
- </body>
- </html>
- --------------- MY PROBLEMS START HERE!
- <!--loggin.php-->
- <!DOCTYPE html>
- <html>
- <head>
- <title>Loggin</title>
- </head>
- <body>
- <?php
- include('databaseConnection.php');
- if (isset($_POST['send']))
- {
- $username = $_POST["username"];
- $password = $_POST["password"];
- $sql = "SELECT password FROM users WHERE userName = '$username' ";
- $stmt = $dbConn->prepare($sql);
- $data = array();
- $stmt->execute($data);
- $res = $stmt->fetch(PDO::FETCH_ASSOC);
- $output = htmlentities(print_r($res, 1));
- echo "<pre>$output</pre>";
- }
- ?>
- <form method ="POST" action ="">
- <input type="text" name="username">
- <input type="password" name="password">
- <input type="submit" name="send">
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement