How to receive data from an html form with PHP [duplicate]

-1

Good afternoon, I'm new to this area and I'm having trouble getting my html form data with my PHP code. My problem is that I am using the Inputs name format the following format name="data [Curriculum] [name]"  however when I enter the Input name in my Php code it does not receive the data. Here is the code I'm using, others I've tried as possible solutions:

<html>
<head>
<title></title>
</head>
<body>

    <form id="formAddCurriculo" class="form-default" enctype="multipart/form-data" method="post" action="conexão.php" accept-charset="utf-8">

    <div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>

<h5 class="title-field whit-padding">Dados Pessoais</h5>

<fieldset class="clearfix mbottom sides-margin">
    <div class="input text">
        <label for="CurriculoName" class="required">Nome Completo</label>
          <input name="data[Curriculo][name]" type="text" class="field field-big" maxlength="255" id="CurriculoName" /></div>

    <div class="input text">
        <label for="CurriculoRg">RG</label>
            <input name="data[Curriculo][rg]" type="text" class="field field-medium" maxlength="14" id="CurriculoRg" /></div>

    <div class="input text required">
        <label for="CurriculoCpf" class="required">CPF</label>
        <input name="data[Curriculo][cpf]" type="text" class="field field-medium cpf" maxlength="50" id="CurriculoCpf" /></div>

    <fieldset class="clearfix sides-margin">
    <div class="submit"><input class="to-upper fright btn-green ts" type="submit" value="Cadastrar" /></div> 

        </fieldset>

                            </form>

</body>
</html>

PHP

<?php
$servername = "localhost";
$database = "**********";
$username = "***********";
$password = "************";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";


// RECEBENDO OS DADOS PREENCHIDOS DO FORMULÁRIO !


$data[Curriculo][name] = $_POST ['$data[Curriculo][name]']; 
$data[Curriculo][rg] = $_POST ['data[Curriculo][rg]']; 
$data[Curriculo][cpf]f = $_POST ['data[Curriculo][cpf]']; 


$Usuarios = "INSERT INTO Usuarios (ID,NomeCompleto, RG, CPF)VALUES((Null,'$data[Curriculo][name]','data[Curriculo][rg]','data[Curriculo][cpf]')";

if (mysqli_query($conn, $Usuarios)) {
      echo "New record created successfully";
} else {
      echo "Error: " . $Usuarios . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);
?>

But you do not get input data, I know it may seem obvious but I could not find the solution in the PHP documentation, and I would not like to rename the Inputs because I have the javascript validation codes and the sheet of style written in this format

    
asked by anonymous 02.08.2018 / 19:13

1 answer

0

You are using the name of the inputs as if they were arrays. Do you really need it? Will you change the data for more than one user? If you do not need it, try to simplify the name of the inputs. You could leave their names as follows:

<input name="name" type="text" class="field field-big" maxlength="255" id="CurriculoName" />

<input name="rg" type="text" class="field field-medium" maxlength="14" id="CurriculoRg" />

<input name="cpf" type="text" class="field field-medium cpf" maxlength="50" id="CurriculoCpf" />

Considering that you simplified the name in the inputs, you could get the input values in PHP like this:

$data["Curriculo"]["name"] = $_POST["name"]; 
$data["Curriculo"]["rg"] = $_POST["rg"]; 
$data["Curriculo"]["cpf"] = $_POST["cpf"];

But again you will be using array. If not needed. You can also simulate the variables.

$name = $_POST["name"]; 
$rg = $_POST["rg"]; 
$cpf = $_POST["cpf"]; 
    
02.08.2018 / 20:09