Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     if( isset($_SESSION['user']) ){
  4.         header("Location: /commerce");
  5.     }
  6.  
  7.     require 'db.php';
  8.  
  9.     $username = '';
  10.     $fname = '';
  11.     $lname = '';
  12.     $email = '';
  13.     $password = '';
  14.     $cpassword = '';
  15.     $message = '';
  16.  
  17.  
  18.     if($_SERVER['REQUEST_METHOD'] == 'POST') {
  19.         $fname = $_POST["fname"];
  20.         $lname = $_POST["lname"];
  21.         $username = $_POST["username"];
  22.         $password = $_POST["passwd"];
  23.         $cpassword = $_POST["cpasswd"];
  24.         $email = $_POST["email"];
  25.  
  26.         if(!empty($username) && !empty($password) && !empty($cpassword) && !empty($email) && !empty($fname) ){
  27.    
  28.             // Enter the new user in the database
  29.             $sql = "INSERT INTO users (username, email, password, fname, lname) VALUES (:username,:email, :password, :fname, :lname)";
  30.             $stmt = $conn->prepare($sql);
  31.  
  32.             $stmt->bindParam(':username', $username);
  33.             $stmt->bindParam(':email', $email);
  34.             $stmt->bindParam(':password', password_hash($password, PASSWORD_BCRYPT));
  35.             $stmt->bindParam(':fname', $fname);
  36.             $stmt->bindParam(':lname',$lname);
  37.  
  38.  
  39.             if( $stmt->execute() ) {
  40.  
  41.                 $message = 'Successfully created new user';
  42.             }
  43.                 else{
  44.                     $message = 'Sorry there must have been an issue creating your account';
  45.                 }
  46.            
  47.            
  48.         }
  49.  
  50.     }
  51.  
  52.  
  53.  
  54. ?>
  55.  
  56.  
  57. <!DOCTYPE html>
  58. <html>
  59.  
  60.  
  61. <head>
  62. <meta charset="utf-8">
  63. <title>Inscription</title>
  64. <link rel="stylesheet" href="layout/css/bootstrap.min.css">
  65.     <link rel="stylesheet" href="layout/css/main.css">
  66. </head>
  67. <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
  68. <table>
  69. <tr>
  70.     <th> nom:</th>
  71.     <td> <input type="text" name="fname" ></td>
  72.  
  73. </tr>
  74. <tr>
  75.     <th>prenom:</th>
  76.     <td><input type="text" name="lname" ></td>
  77.  
  78. </tr>
  79. <tr>
  80.     <th>nom d'utilisateur:</th>
  81.     <td><input type="text" name="username" ></td>
  82.  
  83. </tr>
  84. <tr>
  85.     <th>mot de passe:</th>
  86.     <td><input type="password" name="passwd" ></td>
  87.  
  88. </tr>
  89. <tr>
  90.     <th>confirmer votre mot de passe:</th>
  91.     <td><input type="password" name="cpasswd" ></td>
  92.  
  93. </tr>
  94. <tr>
  95.     <th>adresse email:</th>
  96.     <td><input type="email" name="email"></td>
  97.  
  98. </tr>
  99.  
  100. <tr>
  101.     <th>telephone:</th>
  102.     <td><input type="number" name="" ></td>
  103.  
  104. </tr>
  105. <tr>
  106.     <th></th>
  107.     <td><input type="submit" value="submit" ></td>
  108.  
  109. </tr>
  110.    
  111.  
  112.  
  113.  
  114.  
  115. </table>
  116.  
  117.     <?php
  118.         if ($message != null)
  119.             echo '<br>' . $message . '<br>';
  120.  
  121.  
  122.     ?>
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement