I advocate that each process should be done in its proper place, that is, it would make a file for every thing. But by answering your question, making update
on a single page is possible, but the request will exist the same way.
Let's imagine the following scenario:
Form File
<form id="frmMeuFormulario" method="post" action="salvar.php">
<input type="text" name="nome">
<input type="submit">
</form>
Save action file
<?php
$nome = $_POST["nome"];
salvar($nome);
?>
Each file has its own responsibility, this is much better for future maintenance.
But how would this scenario look in a single file? Well, the first time we opened the file, probably the $_POST
variable does not exist, so we can use the isset
function to check whether or not to execute update
:
Single File
<?php
if (isset($_POST)){
$nome = $_POST["nome"];
salvar($nome);
}
?>
<form id="frmMeuFormulario" method="post">
<input type="text" name="nome">
<input type="submit">
</form>
Notice that in the single file we do not need to have a action
, because it will make a POST
request in the same file. Also note how harder it was to understand what this file is doing.