Advertisement
Guest User

Jeferson Finacio [edited]

a guest
Jun 16th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- Registration with database-->
  2. <?php
  3.  
  4.     $user = 'root';
  5.     $pass = '';
  6.     $db = new PDO( 'mysql:host=localhost;dbname=reguser', $user, $pass );
  7.  
  8.  
  9. ?>
  10.  
  11. <!DOCTYPE html>
  12. <html lang="pt-br">
  13. <head>
  14.     <meta charset="UTF-8">
  15.     <title>Registro de pessoas</title>
  16.     <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
  17.     <style>
  18.         .jumbotron {
  19.             margin-left: auto;
  20.             margin-right: auto;
  21.             width: 50%;
  22.             padding: 0 10%;
  23.         }
  24.     </style>
  25. </head>
  26. <body>
  27.  
  28. <div class="jumbotron">
  29.     <h1> Registro </h1>
  30.    
  31. <?php
  32.  
  33.     if(isset($_POST["inputSubmit"])){
  34.  
  35. ?>
  36.  
  37.     <form name="registration" action="registration.php" method="POST">
  38.  
  39.  
  40.           <div class="form-group">
  41.             <label for="nome">UserName: </label>
  42.             <input type="text" name="username" class="form-control" id="exampleInputEmail1" placeholder="UserName">
  43.           </div>
  44.          
  45.           <div class="form-group">
  46.             <label for="senha">Password</label>
  47.             <input type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  48.           </div>
  49.  
  50.           <div class="form-group">
  51.             <label for="first_name">Firt name: </label>
  52.             <input type="text" name="first_name" class="form-control" id="exampleInputPassword1" placeholder="Firt name">
  53.           </div>
  54.  
  55.           <div class="form-group">
  56.             <label for="surname">Surname: </label>
  57.             <input type="text" name="surname" class="form-control" id="exampleInputPassword1" placeholder="Surname">
  58.           </div>
  59.          
  60.           <div class="form-group">
  61.             <label for="address">Address: </label>
  62.             <input type="text" name="address" class="form-control" id="exampleInputPassword1" placeholder="Address">
  63.           </div>
  64.          
  65.           <div class="form-group">
  66.             <label for="email">E-mail: </label>
  67.             <input type="text" name="email" class="form-control" id="exampleInputPassword1" placeholder="E-mail">
  68.           </div>
  69.          
  70.  
  71.           <button type="submit" class="btn btn-default btn-primary" name="inputSubmit">Submit</button>
  72.     </form>
  73.  
  74. <?php  
  75.     } else {
  76.         $form = $_POST;
  77.         $username = $form['username'];
  78.         $password = $form['password'];
  79.         $first_name = $form['first_name'];
  80.         $surname = $form['surname'];
  81.         $address = $form['address'];
  82.         $email = $form['email'];
  83.  
  84.         echo $form;
  85.    
  86.         $sql = "INSERT INTO usuarios (username, password, first_name, surname, address, email ) VALUES ( :username, :password, :first_name, :surname, :address, :email )";
  87.  
  88.         $query = $db->prepare( $sql );
  89.         $query->execute( array( ':username'=>$username, ':password'=>$password, ':first_name'=>$first_name, ':surname'=>$surname, ':address'=>$address, ':email'=>$email ) );
  90.  
  91.         $result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':first_name'=>$first_name, ':surname'=>$surname, ':address'=>$address, ':email'=>$email ) );
  92.  
  93.         if ( $result ){
  94.           echo "<p>Thank you. You have been registered</p>";
  95.         } else {
  96.           echo "<p>Sorry, there has been a problem inserting your details. Please contact admin.</p>";
  97.         }
  98.     }
  99. ?>
  100. </div>
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement