Hello everyone, I have a question that is the following, I am not able to insert data in PHP, give pfv help :) :) Here is the code: This is my Connection.class.php
<?php
class Conexao {
private $host = "localhost";
private $user = "root";
private $senha = "";
private $banco = "pessoas";
private $conexao;
function __construct($host,$user,$senha,$banco,$conexao) {
$this->host = $host;
$this->user = $user;
$this->senha = $senha;
$this->banco = $banco;
$this->conexao = $conexao;
}
function conectar(){
$this->conexao = mysqli_connect($this->host,$this->user ,$this->senha ,$this->banco );
return $this->conexao;
}
function fecha(){
mysqli_close($this->conexao);
}
}
/*try{
parent::conectar();
if(mysqli_connect_errno() =! 0){
throw new Exception('fudeu');
}
} catch (Exception $e) {
$e->getMessage();
}*/
?>
Insert.class.php:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of Insere
*
* @author felipepietro
*/
require_once 'Conexao.class.php';
class Insere extends Conexao {
private $nome;
private $sobrenome;
function getNome() {
return $this->nome;
}
function getSobrenome() {
return $this->sobrenome;
}
function setNome($nome) {
$this->nome = $nome;
}
function setSobrenome($sobrenome) {
$this->sobrenome = $sobrenome;
}
function insere(){
$link = parent::conectar();
$sql = "INSERT INTO pessoas(NULL,'nome','sobrenome') VALUES ('{$this->setNome()}','{$this->setSobrenome()}')";
$res = mysqli_query($link, $sql);
}
}
this the valida-cadastro.php:
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
require_once 'classes/Conexao.class.php';
require_once 'classes/Insere.class.php';
$insere = new Insere();
$insere->getNome($_POST['nome']);
$insere->getSobrenome($_POST['sobre']);
$insere->insere();
?>
and finally my HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form method="POST" action="valida-cadastro.php">
<label>
Nome:
<input type="text" name="nome" id="nome">
</label>
<label>
Sobrenome:
<input type="text" name="sobre" id="sobre">
</label>
<input type="submit" value="Cadastrar">
</form>
</body>
</html>