How to perform Submit in a form with input text and two inputs file?

Asked

Viewed 108 times

2

I made a registration form where the user must fill name and CPF , and attach a photo of RG and another selfie.

I already created the database on mysql, however the submit doesn’t work. When I remove the inputs file, then it works.

In the mysql I created two columns of the type blob to receive both images.

Does anyone know why Submit doesn’t work? The screen doesn’t update, just nothing happens.

Follow the form code below.

<form id="main-contact-form" action="cadastroAdd.php" method="post" enctype="multipart/form-data">
    <input type="text" name="nome" id="nome" placeholder="Nome completo" required onkeyup="maiusculas()" autofocus>&nbsp;<b><font color="red">*</font></b><input type="hidden" name="prazo" id="prazo" ><br><br>
    <input type="text" name="cpf" id="cpf" placeholder="CPF" required OnKeyPress="formatar('###.###.###-##', this)" maxlength="14">&nbsp;<b><font color="red"> Menor de idade ou não tem CPF <input type="checkbox" name="menor"    id="menor" value="-dependente"/>*</font></b><br>*Caso seja menor de idade e ainda não possua CPF, insira o CPF do Responsável. Vale ressaltar que a retirada do documento só poderá ser feita pelo titular do CPF cadastrado.<br><br>
    <input type="text" name="nascimento" id="nascimento" placeholder="Data de Nascimento" required OnKeyPress="formatar('##/##/####', this)" maxlength="10">&nbsp;<b><font color="red">*</font></b>
    <br>
    <br>
    <input type="text" name="telefone" id="telefone" placeholder="Telefone(Whatsapp)" required OnKeyPress="formatar('##-#####-####', this)" maxlength="13">&nbsp;<b><font color="red">*</font></b><br>
    (99-99999-9999)
    <br><br>
    <input type="email" name="email" id="email" placeholder="E-mail"><br><br>
    Adicione uma foto de rosto: <input type="file" name="foto" id="foto" class="anexo">&nbsp;<b><font color="red">*</font></b><br><br>
    Adicione uma imagem do seu documento com foto(RG ou CNH): <input type="file" name="documento" id="documento" class="anexo">&nbsp;<b><font color="red">*</font></b><br><br>      
    <input type="submit" name="enviar" value="Enviar">
</form> <br><br>

php cadastre.

$conexao->query("set names utf8");
$nome = $_POST['nome'];
$cpf = $_POST['cpf'];
$nascimento = $_POST['nascimento'];
$telefone = $_POST['telefone'];
$email = $_POST['email'];
$prazo = $_POST['prazo'];
$foto = $FILE['foto'];
$documento = $FILE['documento'];
$menor = $_POST['menor'];
$sql = "INSERT INTO `epiz_24359771_paraqueradical`.`usuarios` (`nome`, `cpf`, `nascimento`, `telefone`, `email`, `prazo`)  values ('$nome','$menor''$cpf','$nascimento','$telefone','$email','$prazo','$foto','$documento')";
$salvar = mysqli_query($conexao, $sql);
$linhas = mysqli_affected_rows($conexao);
mysqli_close($conexao);
?>
<?php
if ($linhas == 1) {
    echo "Cadastro efetuado com Sucesso!!";


} else {
    print "Cadastro não efetuado.";

}

?>
<a class="botao" href="cadastro.php"><input type="button" id="voltar" value="VOLTAR"></a>

  • Do you want with or without type=files?

  • with type files . I want you to upload everything to the mysql I’ve already created. ie. the 2 photos and user data

  • Add the inputs you want to your code...

  • are already there. are 5 inputs text , 1 checkbox and 2 files.

  • How’s your cadastroAdd.php this is the file you are receiving and should process the request sent by the form and save the data in mysql.

  • I don’t see the change in the enctype...

  • Has problems in the register... '$menor''$cpf' has no comma in the Insert of this data. In addition you are trying to insert in 6 fields and sending 9 variables... This only in Insert. I think you’d better post the errors that are shown.

Show 2 more comments

2 answers

1

Friend by default the form property enctype has the value application/x-www-form-urlencoded.

To send files you need to specify enctype=multipart/form-data.

<form id="main-contact-form" action="cadastroAdd.php" method="POST" enctype="multipart/form-data">
  • includes enctype="Multipart/form-data", and nothing

  • Edit your question with changes made...

  • I edited upstairs

  • What is the name of the file containing the form?

  • ...... php.

  • Have problems in the registration.

  • Include at the top of the 2 files ini_set('display_errors', 1);&#xA;ini_set('display_startup_errors', 1);&#xA;error_reporting(E_ALL); And put the errors...

  • is this php? put at the top of the two files? .php registration and.php

  • inserted in both. but still nothing happens. it seems that the error is in the.php register file, because it is not even submerged. it doesn’t even search the action page. when I remove the input file it works

Show 4 more comments

1

Allan, there were a lot of typos in your files. I fixed them for you. You were using

$FILE

when the right thing is $_FILES[].

Something else in your insert there was an error between

'$less'$Cpf',

missing a comma.

For you to have a feedback from your system for when there is error in your query, insert, update, delete etc vc use at the end of their mysqli_query() the following command:

or mysqli_error();

With this, if there is error in your query will return error.

Fixed your registration fileAdd.php:

<?php

//ini_set("display_errors",true);

ini_set('default_charset', 'utf-8');
include("conexao.php");

/* AQUI ESTÃO OS DADOS VINDOS DO FORMULARIO*/
echo "<pre>";
    var_dump($_POST);
echo "</pre>";

echo "<pre>";
    var_dump($_FILES);
echo "</pre>";

$conexao->query("set names utf8");
$nome = $_POST['nome'];
$cpf = $_POST['cpf'];
$nascimento = $_POST['nascimento'];
$telefone = $_POST['telefone'];
$email = $_POST['email'];
$prazo = $_POST['prazo'];
$foto = $_FILES['foto'];
$documento = $_FILES['documento'];
$menor = $_POST['menor'];

$sql = "INSERT INTO `epiz_24359771_paraqueradical`.`usuarios` (`nome`, `cpf`, `nascimento`, `telefone`, `email`, `prazo`)  values ('$nome','$menor','$cpf','$nascimento','$telefone','$email','$prazo','$foto','$documento')";
$salvar = mysqli_query($conexao, $sql) or mysqli_error();
$linhas = mysqli_affected_rows($conexao);
mysqli_close($conexao);
?>
<?php
if ($linhas == 1) {
    echo "Cadastro efetuado com Sucesso!!";


} else {
    print "Cadastro não efetuado.";

}

?>

<a class="botao" href="cadastro.php">
<input type="button" id="voltar" value="VOLTAR">
</a>

Note that I used var_dump($_POST) << this shows all the POST that are coming from your form, just as I used var_dump($_FILES) where it shows the files.

COMMENT THESE VAR_DUMPS for your code to work normally.

  • I’ll try here, but the comma question is not to have anyway. because I want in the column of mysql between the two information. i.e., the value of the variable $minor ,followed by the variable $Cpf. these two information in the same field.

  • So Leandro Alfredo, the point is that the page does not go to the registersAdd.php.

  • I click send and nothing happens. so I think the error is somewhere in the.php register. When I remove the input file from the form. the data is normally saved in mysql. but you needed it to send the photos as well. ?

  • Dude, if you put your code up there there there is no mistake in your file. You are wrong there. As what you went through and what I posted is perfectly working.

  • There are more mistakes in insert... He is trying to insert into 6 declared fields a total of 9 different values... this generates the error: Error Code: 1136. Column count doesn't match value count at row .... Which means... The column count does not correspond to the value count in the row

Browser other questions tagged

You are not signed in. Login or sign up in order to post.