Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2.  
  3. if (isset($_POST['button'])){
  4.     include_once 'db.inc.php' ; //ou on a la db pour utiliser $conn
  5.  
  6.     // $firstname = mysqli_real_escape_string($conn, $_POST['first']); // to protect from sql injection attack
  7.  
  8.     $firstname = $_POST['first'];
  9.     $lastname = $_POST['last'];
  10.     $email = $_POST['email'];
  11.     $uid = $_POST['uid'];
  12.     $pwd = $_POST['pwd'] ;
  13.  
  14.     if (empty($firstname) || empty($lastname) || empty($email) || empty($uid) || empty($pwd)){
  15.         header("Location: ../home.php?signup=empty") ;
  16.         exit() ;
  17.     }else{
  18.         $sql = "insert into users (firstname,lastname,email,uid,pwd) values(?,?,?,?,?);";
  19.         $stmt = mysqli_stmt_init($conn) ;
  20.         if(!mysqli_stmt_prepare($stmt, $sql)) {
  21.             echo "operation failed " ;
  22.         }else {
  23.             mysqli_stmt_bind_param($stmt,"sssss",$firstname,$lastname,$email,$uid,$pwd);
  24.             mysqli_stmt_execute($stmt) ;
  25.             header("Location: ../home.php?signup=success") ;
  26.         }
  27.             /*
  28.             // mysqli_query  :you send the cmd request and returne ressources if success else returns false
  29.             $result = mysqli_query ( $conn, $sql ) ;
  30.             //for test of connection
  31.             if (mysqli_connect_errno())
  32.             {
  33.                 echo "Failed to connect to MySQL: " . mysqli_connect_error();
  34.             }
  35.             header("Location: ../home.php?signup=success") ;
  36.             */
  37.  
  38.  
  39.     }
  40. }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement