Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>My PHP Insert</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
- </head>
- <body>
- <div class="container container-form">
- <div class="panel panel-primary">
- <div class="panel-body">
- <form class="form-horizontal" method="post" name="myForm" id="myForm" action="insert.php" >
- <div class="form-group">
- <label class="col-sm-6"> Username </label>
- <div class="col-sm-6">
- <input type="email" pattern="[^ @]*@[^ @]*" name="username" class="form-control" id="username" required>
- </div>
- </div>
- <div class="form-group">
- <label class="col-sm-6"> Password </label>
- <div class="col-sm-6">
- <input type="password" name="password" class="form-control" id="password" required>
- </div>
- </div>
- <div class="form-group">
- <div class="col-sm-6">
- <button type="submit" class="btn btn-success"> Save </button>
- <button type="reset" class="btn btn-danger"> Clear </button>
- </div>
- </div>
- </form>
- <?php
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- require_once 'config.php';
- $username=$_POST['username'];
- $password=password_hash($_POST['password'], PASSWORD_DEFAULT);
- try{
- $sql = "INSERT INTO users (username,password ) VALUES (:username,:password)";
- $stmt = $pdo->prepare($sql);
- // Bind parameters to statement
- $stmt->bindParam(':username', $username, PDO::PARAM_STR);
- $stmt->bindParam(':password', $password, PDO::PARAM_STR);
- $stmt->execute();
- echo "Records inserted successfully.<br>";
- } catch(PDOException $e){
- die("ERROR: Could not able to execute $sql. " . $e->getMessage());
- }
- }
- ?>
- </div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement