Advertisement
lowheartrate

Registration page (Write to DB)

Jun 1st, 2015
374
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         <?php
  2.             if(empty( $_POST ) ) {
  3.         ?>
  4.  
  5.         <div id="reg_form" style="background-color: #e6e6e6;">
  6.             <h1 style="font-weight: bold; text-align: center;">Register an account</h1><br>
  7.  
  8.             <form name="registeraccount" method="POST">
  9.                 <label for 'firstname'>First name: </label><br>
  10.                 <input type="text" name="firstname" placeholder="First Name" reqiured/>
  11.                     <br>
  12.                 <label for 'lastname'>Last Name: </label><br>
  13.                 <input type="text" name="lastname" placeholder="Last Name" required/>
  14.                     <br>
  15.                 <label for 'username'>Username: </label><br>
  16.                 <input type="text" name="username" placeholder="Username" required/>
  17.                     <br>
  18.                 <label for 'password'>Password: </label><br>
  19.                 <input type="password" name="password" placeholder="Password" required/>
  20.                     <br>
  21.                 <label for 'email'>Email Address: </label><br>
  22.                 <input type="email" name="email" placeholder="Email Address" required/>
  23.                     <br><br>
  24.                 <button type="submit">Register account</button><br><br>
  25.             </form>
  26.         </div>
  27.  
  28.         <?php
  29.             } else {
  30.                 $servername = "198.71.225.55:3306";
  31.                 $username = "";
  32.                 $password = "";
  33.                 $dbname = "heartfx_users";
  34.                 $db = new PDO( 'mysql:host=198.71.225.55:3306;dbname=heartfx_users', $username, $password );
  35.  
  36.                 $form = $_POST;
  37.                 $firstname = $form['firstname'];
  38.                 $lastname = $form['lastname'];
  39.                 $username = $form['username'];
  40.                 $password = $form['password'];
  41.                 $email = $form['email'];
  42.  
  43.                 $sql = "INSERT INTO Users ( firstname, lastname, username, password, email )
  44.                 VALUES ( :firstname, :lastname, :username, :password, :email )";
  45.  
  46.                 $query = $db->prepare( $sql );
  47.                 $result = $query->execute( array( ':firstname'=>$firstname, ':lastname'=>$lastname, ':username'=>$username, ':password'=>$password, ':email'=>$email ) );
  48.             }
  49.         ?>
Advertisement
RAW Paste Data Copied
Advertisement