Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.     $host = 'localhost';
  3.     $db   = 'DB_SELECTION';
  4.     $user = 'DB_USERNAME';
  5.     $pass = 'DB_PASSWORD';
  6.     $charset = 'utf8mb4';
  7.  
  8.     $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  9.     try {
  10.         $opt = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ];
  11.         $conn = new PDO($dsn, $user, $pass, $opt);
  12.     }
  13.     catch(PDOException $e) {
  14.         echo "Connection failed: " . $e->getMessage();
  15.     }
  16.  
  17.  
  18.     if (isset($_POST["btnreg"]))
  19.     {
  20.         $query = "INSERT INTO users (username, password, email, mobile, address) VALUES (:username, :password, :email, :mobile, :address)";
  21.         $result = $connect->prepare($query);
  22.         $result->bindParam(":username", $username);
  23.         $result->bindParam(":password", $password);
  24.         $result->bindParam(":email", $email);
  25.         $result->bindParam(":mobile", $mobile);
  26.         $result->bindParam(":address", $address);
  27.         $username = $_POST["username"];
  28.         $password = $_POST["password"];
  29.         $email = $_POST["email"];
  30.         $mobile = $_POST["mobile"];
  31.         $address = $_POST["address"];
  32.         if ($result->execute())
  33.         {
  34.             echo "Insert successfuly";
  35.         } else {
  36.             echo "Inser unsuccessfil";
  37.         }
  38.     } else {
  39.         echo "Error, you did not submit the form properly"
  40.     }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement