Advertisement
Yousuf1791

customer.php

Apr 20th, 2022
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1. <?php
  2.  
  3. class customer{
  4.     private $server = "localhost";
  5.     private $user = "root";
  6.     private $pass = "";
  7.     public $dbname = "test4";
  8.  
  9.     function __construct(){
  10.         $this->dbcon = new PDO("mysql:host=$this->server; dbname=$this->dbname", $this->user, $this->pass);
  11.     }
  12.  
  13.         function insertData($p){
  14.  
  15.         try{
  16.             $insert_query = "insert into customer(name, age, gender, email) values(:n, :a, :g, :e)";
  17.  
  18.                     $result = $this->dbcon->prepare($insert_query);
  19.  
  20.                     $result->bindParam("n", $_POST['name']);
  21.                     $result->bindParam("a", $_POST['age']);
  22.                     $result->bindParam("g", $_POST['gender']);
  23.                     $result->bindParam("e", $_POST['email']);
  24.  
  25.                     $result->execute();
  26.  
  27.                     ?>
  28.                     <script type="text/javascript">
  29.                         window.location.href="add.php";
  30.                     </script>
  31.                     <?php
  32.         }catch(PDOException $e){
  33.             echo "Error :" .$e->getMessage();
  34.         }
  35.  
  36.        
  37.  
  38.     }
  39.  
  40.    
  41.  
  42. }
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement