1
I created the file functions.php
and includes in it the function add()
, but when I call her on the page add.php
by command require_once
a fatal error appears.
Fatal error: Uncaught Error: Call to Undefined Function view() in C: xampp htdocs Lester customers add.php:3 Stack trace: #0 {main} thrown in C: xampp htdocs Lester customers add.php on line 3
Follow codes:
This is from the functions.php file
<?php
require_once('../config.php');
require_once(DBAPI);
$customers = null;
$customer = null;
/**
* Listagem de Clientes
*/
function index() {
global $customers;
$customers = find_all('customers');
}
/**
* Cadastro de Clientes
*/
function add() {
if (!empty($_POST['customer'])) {
$today =
date_create('now', new DateTimeZone('America/Sao_Paulo'));
$customer = $_POST['customer'];
$customer['modified'] = $customer['created'] = $today->format("Y-m-d H:i:s");
save('customers', $customer);
header('location: index.php');
}
}
/** * Visualização de um Cliente
*/
function view($id = null) {
global $customer;
$customer = find('customers', $id);
}
?>
E esse é do arquivo add.php
<?php
require_once('functions.php');
add();
?>
<?php include(HEADER_TEMPLATE); ?>
<h2>Novo Cliente</h2>
<form action="add.php" method="post">
<!-- area de campos do form -->
<hr />
<div class="row">
<div class="form-group col-md-7">
<label for="name">Nome / Razão Social</label>
<input type="text" class="form-control" name="customer['name']">
</div>
<div class="form-group col-md-3">
<label for="campo2">CNPJ / CPF</label>
<input type="text" class="form-control" name="customer['cpf_cnpj']">
</div>
<div class="form-group col-md-2">
<label for="campo3">Data de Nascimento</label>
<input type="text" class="form-control" name="customer['birthdate']">
</div>
</div>
Códigos do arquivo view.php
<?php
require_once('functions.php');
view($_GET['id']);
?>
<?php include(HEADER_TEMPLATE); ?>
<h2>Cliente <?php echo $customer['id']; ?></h2>
<hr>
<?php if (!empty($_SESSION['message'])) : ?>
<div class="alert alert-<?php echo $_SESSION['type']; ?>"><?php echo $_SESSION['message']; ?></div>
<?php endif; ?>
<dl class="dl-horizontal">
<dt>Nome / Razão Social:</dt>
<dd><?php echo $customer['name']; ?></dd>
<dt>CPF / CNPJ:</dt>
<dd><?php echo $customer['cpf_cnpj']; ?></dd>
<dt>Data de Nascimento:</dt>
<dd><?php echo $customer['birthdate']; ?></dd>
</dl>
<dl class="dl-horizontal">
<dt>Endereço:</dt>
<dd><?php echo $customer['address']; ?></dd>
<dt>Bairro:</dt>
<dd><?php echo $customer['hood']; ?></dd>
<dt>CEP:</dt>
<dd><?php echo $customer['zip_code']; ?></dd>
<dt>Data de Cadastro:</dt>
<dd><?php echo $customer['created']; ?></dd>
</dl>
Can you tell me why?
This error does not even refer to
function add()
that you created and not even the archiveadd.php
and yes the functionview()
and the fileview.php
. It’s hard to help you by telling you what’s going on without seeing the code. Put the tbm sources in the question for a better analysis.– Fernando VR
Sorry it gave error in the two files what has the add() function and what has the view function().
– Fabio Ozuna
I understand, give an edited there in your question, and post the code you are using the two files that is giving error, and the file that calls by the command
require_once
. You can’t help without seeing what you’ve done, you know?– Fernando VR
Code following. This is from the add.php <?php require_once('functions.php'); add(); ? > <? php include(HEADER_TEMPLATE); ? > <H2>New Client</H2> <form action="add.php" method="post"> <!-- field area of the form --> <hr /> <div class="Row"> </div> This is the one of the functions.php Function add() { if (!Empty($_POST['Customer'])) { $Today = date_create('now', new Datetimezone('America/Sao_paulo')); $Customer = $_POST['Customer']; $Customer['modified'] = $Customer['created'] = $Today->format("Y-m-d
– Fabio Ozuna
You need to put the codes in question and formatted for better reading. At this link you can see how the formatting should be done: https://answall.com/editing-help#code
– Fernando VR
Sorry I’m unable to format the question is my first participation here in the forum. Can I send a screen print? It would help?
– Fabio Ozuna
I made an edit on your question by formatting your code. When you enter some source code in your question, select all code and hit the CTRL+K keys for pre-formatting.
– Fernando VR
Apparently your code for the execution of the add() function is correct, however the error of the view() function is not yet related to this code you posted. Because it does not appear the so-called view() as the indication of the error. Take a look if you’re posting the right file code about the error you’re making. Can publish error prints on your question as well. The more information you pass on, the better.
– Fernando VR
Both the add.php file and the view.php have the same baseline and the fatal error always points only to the situation of line 3 which is where the Function information is
– Fabio Ozuna
I discovered the mistake. It was a very basic thing and they waste a lot of time. I created two functions.php files one in the inc folder and the other in the custommers folder and the files mentioned here were referencing the inc folder, when they should reference the custommers folder. I thank you for your attention and for trying to help.
– Fabio Ozuna
The error you posted is strange, because it says of a view() function that is not even being called by the add.php file. Try to give a look if you have posted the error correctly, and if you are not giving any other error than that, pq the error you posted and the codes that were posted are not tapping. .
– Fernando VR
I reviewed the references and now it’s all worked out.
– Fabio Ozuna
Ahh ok, I was finding it really strange, because the code you showed was not matching the error. But I’m glad you found the solution. Hugs
– Fernando VR
Gratitude for the support
– Fabio Ozuna