1
Query with Insert
public function CadastrarArquivos($pdo, $arq_nome, $a_areaid, $u_userid){ $ins = $pdo->prepare("INSERT INTO arq_arquivos(arq_nome, a_area_a_areaid, u_usuarios_u_useid) VALUES(:arq_nome, :a_areaid, :u_userid)" ); $ins->bindParam(":arq_nome",$arq_nome); $ins->bindParam(":a_areaid",$a_areaid); $ins->bindParam(":u_userid",$u_userid);
$obj = $ins->execute();
return ($obj) ? $obj : false;<code>
//Php function to register
function cadastrarArquivo($app){
$param = array("titulo"=>$app->site_titulo,
"pagina" => "formarquivos",
"dados" => array(
"tituloform" => "Cadastrar novo Arquivo",
"action"=>"execCadastrarArquivo",
"arq_arqid"=>"",
"arq_nome"=>"",
"labelbtnsubmit"=>"Cadastrar"
)
);
$app->loadView("Admin",$param);
}
function execCadastrarArquivo($app){
$admin = $app->loadModel("Admin");
$arq_nome = ($_POST["arq_nome"]);
$a_areaid = 1; /*marque 1 para selecionar uma area já existente de teste.*/
$u_userid = $_SESSION["u_userid"];
$obj = $admin->CadastrarArquivos($app->conexao, $arq_nome, $a_areaid, $u_userid);
if($obj) {
$mensagem = "Cadastro efetuado com sucesso!";
} else {
$mensagem = "Cadastro falhou!";
}
$this->listarareainicial($app,$admin,$mensagem);
}<code>
//That way there is no mistake, but do not register in the bank.
html form
<form method="POST" action="index.php?m=admin&c=minhaarea&a=<?=$tpl["dados"]["action"]?>">
<div class="row">
<div class="col-xs-2">
<strong>Nome do arquivo:</strong>
</div>
<div class="col-xs-10">
<input type="text" name="arq_nome" class="col-xs-12 form-control"
value="<?=$tpl["dados"]["arq_nome"]?>" autofocus required />
</div>
</div>
<div class="row marginTop">
<div class="col-xs-2">
<input type="submit" value="<?=$tpl["dados"]["labelbtnsubmit"]?>" class="btn btn-primary btn-large" />
</div>
</div>
<input type="hidden" value="<?=$tpl["dados"]["arq_arqid"]?>" name="arq_arqid" />
</form>
Not that it can’t work that way, but it would be nice to simplify the code. If you have
function CadastrarArquivos
,function cadastrarArquivo
andfunction execCadastrarArquivo
, something doesn’t look very good in the way of organizing the code.– Bacco
Then Function Register Files is separated, together only with the query, already the Register File returns to the user a page with the form to type, and to send has a button that calls the Function execCadastrarfile.
– will