SHARE
TWEET

Untitled

a guest Jun 17th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Connection extends mysqli{
  3.   //Connection data
  4.   private $DB_NAME = "datos";
  5.   private $DB_TABLE = "user";
  6.   private $DB_HOST = "localhost";
  7.   private $DB_PASSWORD = "password";
  8.   private $DB_USER = "root";
  9.   public $DB_CHARSET = "utf8";
  10.  
  11.   //Constructor
  12.   public function __construct(){
  13.     parent::__construct($this->DB_HOST,$this->DB_USER,$this->DB_PASSWORD,$this->DB_NAME);
  14.     if ($this->connect_errno) echo "<div class='mensaje'>Error:
  15.       {$this->connect_errno} -> {$this->connect_error}</div>";
  16.     $this->set_charset($this->DB_CHARSET);
  17.   }
  18.  
  19.   //Insert new record
  20.   public function insert($id,$name,$password){
  21.     $sql_comand = "INSERT INTO {$this->DB_TABLE} VALUES (?,?,?)";
  22.     if(!($sentence = $this->prepare($sql_comand))){
  23.       echo "Error(prepare): {$this->connect_errno} -> {$this->connect_error}";
  24.     }
  25.     $sentence = $this->bind_param("iss",$id,$name,$password);
  26.     $sentence->execute();
  27.     $sentence->close();
  28.   }
  29.   public function select(){
  30.     $sql_comand = "SELECT * FROM {$DB_TABLE}";
  31.     $querys = $this->query($sql_comand);
  32.     while ($record = $querys->fetch_assoc()) {
  33.       echo "ID: {$record['id']}";
  34.       echo "name: {$record['name']}";
  35.       echo "password: {$record['password']}";
  36.     }
  37.   }
  38.  
  39. }
  40. ?>
  41.      
  42. <form action="<?php htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
  43.     <input type="number" class="id" name="id" maxlength="11" placeholder="ID"><br>
  44.     <input type="text" name="name" maxlength="35" placeholder="Name"><br>
  45.     <input type="password" name="password" maxlength="60" placeholder="Password"><br>
  46.     <input type="submit" name="button" value="Submit">
  47. </form>
  48.  
  49. <?php
  50.   require "connection.php";
  51.  
  52.   if(isset($_POST["button"])){
  53.     $con = new Connection();
  54.     $id = htmlspecialchars($_POST["id"]);
  55.     $name = htmlspecialchars($_POST["name"]);
  56.     $password = htmlspecialchars($_POST["password"]);
  57.     $con->insert($id,$name,$password);
  58.     $con->close();
  59.   }
  60. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top