Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- if($_POST){
- // instantiate Empresa object
- include_once 'php/Empresa.php';
- $empresa = new Empresa($db);
- // set Empresa property values
- $empresa->razao_social = $_POST['razaosocial'];
- $empresa->cnpj = $_POST['cnpj'];
- $empresa->inscricao_estadual = $_POST['inscricaoestadual'];
- // create the Empresa
- if($empresa->create()){
- echo "<div class=\"alert alert-success alert-dismissable\">";
- echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>";
- echo "Empresa Cadastrada.";
- echo "</div>";
- }
- // if unable to create the Empresa, tell the user
- else{
- echo "<div class=\"alert alert-danger alert-dismissable\">";
- echo "<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">×</button>";
- echo "Erro ao Cadastrar.";
- echo "</div>";
- }
- }
- ?>
- // Class Empresa
- <?
- public class Empresa{
- //base de dados e nome da tabela
- private $conn;
- private $table_name = "cadastro_emp";
- //propriendades da Classe
- $public razao_social;
- $public cnpj;
- $public inscricao_estadual;
- public function __construct($db){
- $this->conn = $db;
- }
- // create product
- function create(){
- // to get time-stamp for 'created' field
- $this->getTimestamp();
- //write query
- $query = "INSERT INTO
- " . $this->table_name . "
- SET
- razao_social = ?, cnpj = ?, inscricao_estadual = ?";
- $stmt = $this->conn->prepare($query);
- $stmt->bindParam(1, $this->razao_social);
- $stmt->bindParam(2, $this->cnpj);
- $stmt->bindParam(3, $this->inscricao_estadual);
- if($stmt->execute()){
- return true;
- }else{
- return false;
- }
- }
- }
- //Class Conexão
- <?php
- class Database{
- // specify your own database credentials
- private $host = "127.0.0.1";
- private $db_name = "sisim";
- private $username = "root";
- private $password = "";
- public $conn;
- // get the database connection
- public function getConnection(){
- $this->conn = null;
- try{
- $this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password);
- }catch(PDOException $exception){
- echo "Connection error: " . $exception->getMessage();
- }
- return $this->conn;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement