0
hello,
I am studying PHP but I have a code that is not storing in BD, I have debugged it all, the error tests n return nothing, it is only blank but n stores
follows code:
<?php
require 'classeFornecedor.php';
$fornecedor = new fornecedor();
$fornecedor->nome = filter_input(INPUT_POST, 'nome', FILTER_SANITIZE_STRING);
$fornecedor->cnpj = filter_input(INPUT_POST, 'cnpj', FILTER_SANITIZE_STRING);
$fornecedor->cadastrarFornecedor();
?>
<?php
class fornecedor{
private $con;
private $nome;
private $cnpj;
public function __set($atributo, $valor){
$this->$atributo = $valor;
}
public function __get($atributo){
return $this->$atributo;
}
public function cadastrarFornecedor(){
require 'classeConexao.php';
$query = "INSERT INTO('nome', 'cnpj') VALUES ('$this->nome', '$this->cnpj')";
$resultado = mysqli_query($conn, $query);
return 'cadastro.php';
}
}
?>
<?php
$host = "localhost";
$database = "agendamento";
$user = "root";
$pass = "";
$conn = mysqli_connect($host, $user, $pass, $database);
mysqli_select_db($conn,$database);
?>
<div id="menu">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="index.php">Login</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavAltMarkup">
<div class="navbar-nav">
<a class="nav-item nav-link" href="agendamento.php">Agendamento <span class="sr-only">(current)</span></a>
<a class="nav-item nav-link active" href="cadastro.php">Cadastro</a>
<a class="nav-item nav-link" href="consulta.php">Consulta</a>
</div>
</div>
</nav>
</div>
<header>
<img id="imagem" alt="Conibase - do basico ao acabamento" src="logosite.png">
</header>
<div class="shadow-lg p-3 mb-5 bg-white rounded" id="cadastro">
<header>
<h2 id="head">
Cadastro de Fornecerdor
</h2>
</header>
<form action="cadastro-int.php" method="post" >
<input name="nome" class="form-control form-control-sm" id="fornecedor" type="text" placeholder="Nome">
<input name="cnpj" class="form-control form-control-sm" id="cnpj" type="text" placeholder="CNPJ">
<button type="submit" id="botao" class="btn btn-outline-danger">Cadastrar</button>
</form>
</div>
Not giving another error too? the variables you are assigning a value, are private, in case you should use __set
– Guilherme Henriques