Advertisement
C42759

TELEGRAM PHP RIO #1

Jun 16th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- Registration with database-->
  2. <?php
  3.     // PARA UM MELHOR DESEMPENHO, ISTO DEVE SER COLOCADO NUM FICHEIRO CHAMADO EX.: db_connection.php
  4.     $user = 'root';
  5.     $pass = '';
  6.     $db = new PDO( 'mysql:host=localhost;dbname=reguser', $user, $pass );
  7.    
  8.     // E AQUI COLOCAR required_once("db_connection.php");
  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.         <?php
  31.             if(isset($_POST["inputSubmit"])){
  32.         ?>
  33.             <form name="registration" action="registration.php" method="POST">
  34.  
  35.  
  36.                   <div class="form-group">
  37.                     <label for="nome">UserName: </label>
  38.                     <input type="text" name="username" class="form-control" id="exampleInputEmail1" placeholder="UserName">
  39.                   </div>
  40.                  
  41.                   <div class="form-group">
  42.                     <label for="senha">Password</label>
  43.                     <input type="password" name="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
  44.                   </div>
  45.  
  46.                   <div class="form-group">
  47.                     <label for="first_name">Firt name: </label>
  48.                     <input type="text" name="first_name" class="form-control" id="exampleInputPassword1" placeholder="Firt name">
  49.                   </div>
  50.  
  51.                   <div class="form-group">
  52.                     <label for="surname">Surname: </label>
  53.                     <input type="text" name="surname" class="form-control" id="exampleInputPassword1" placeholder="Surname">
  54.                   </div>
  55.                  
  56.                   <div class="form-group">
  57.                     <label for="address">Address: </label>
  58.                     <input type="text" name="address" class="form-control" id="exampleInputPassword1" placeholder="Address">
  59.                   </div>
  60.                  
  61.                   <div class="form-group">
  62.                     <label for="email">E-mail: </label>
  63.                     <input type="text" name="email" class="form-control" id="exampleInputPassword1" placeholder="E-mail">
  64.                   </div>
  65.                  
  66.  
  67.                   <button type="submit" class="btn btn-default btn-primary" name="inputSubmit">Submit</button>
  68.             </form>
  69.         <?php
  70.             } else {
  71.  
  72.                 $form = $_POST;
  73.                 $username = $form['username'];
  74.                 $password = $form['password'];
  75.                 $first_name = $form['first_name'];
  76.                 $surname = $form['surname'];
  77.                 $address = $form['address'];
  78.                 $email = $form['email'];
  79.  
  80.                 // echo $form; ??? PARA QUE SERVE ISTO???
  81.  
  82.                 $sql = "INSERT INTO usuarios (username, password, first_name, surname, address, email ) VALUES ( :username, :password, :first_name, :surname, :address, :email )";
  83.  
  84.                 $query = $db->prepare( $sql );
  85.                 $query->execute( array( ':username'=>$username, ':password'=>$password, ':first_name'=>$first_name, ':surname'=>$surname, ':address'=>$address, ':email'=>$email ) );
  86.  
  87.                 $result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':first_name'=>$first_name, ':surname'=>$surname, ':address'=>$address, ':email'=>$email ) );
  88.  
  89.                 if ( $result ){
  90.                     echo "<p>Thank you. You have been registered</p>";
  91.                 } else {
  92.                     echo "<p>Sorry, there has been a problem inserting your details. Please contact admin.</p>";
  93.                 }
  94.             }
  95.         ?>
  96.         </div>
  97.     </body>
  98. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement