Problems saving information to the database

0

I have this code, but for some reason it is not saving the information in the database. Can someone explain to me what is wrong with the code?

<?php
    require_once('functions.php');
    add();
?>

<h2>Novo Cliente</h2>

<form action="add.php" method="post">
    <hr />
    <div class="row">
        <div class="form-group col-md-7">
            <label for="name">Nome</label>
            <input type="text" class="form-control" id="name" name="customer['name']">
        </div>
    </div>
    <div class="row">
        <div class="form-group col-md-3">
            <label for="cpf">CPF</label>
            <input type="text" class="form-control" id="cpf" name="customer['cpf']">
        </div>
    </div>
</form>
<!--/////////////////////////////////////////////////////////////////////////////////////////////////////////
Este código esta em outro arquivo-->
<?php
function add() {
	if (!empty($_POST['customer'])) {
		$customer = $_POST['customer'];
		save('pessoa', $customer);
		header('location: index.php');
	}
}
?>
<!--/////////////////////////////////////////////////////////////////////////////////////////////////////////
Este código esta em outro arquivo-->
<?php
function save($table = null, $data = null) {
	$database = open_database();
	$columns = null;
	$values = null;
	foreach ($data as $key => $value) {
		$columns .= trim($key, "'") . ",";
		$values .= "'$value',";
	}
	$columns = rtrim($columns, ',');
	$values = rtrim($values, ',');
	$sql = "INSERT INTO " . $table . "($columns)" . " VALUES " . "($values);";
	try {
		$database->query($sql);
		$_SESSION['message'] = 'Registro cadastrado com sucesso.';
		$_SESSION['type'] = 'success';
	} catch (Exception $e) {
		$_SESSION['message'] = 'Nao foi possivel realizar a operacao.';
		$_SESSION['type'] = 'danger';
	}
	close_database($database);
}
?>
    
asked by anonymous 29.12.2017 / 16:23

0 answers