-1
Good afternoon, I am new in this area and I am having problems to receive data from my html form with my PHP code. My problem is I’m using for the name of Inputs the following format name="date[Resume][name]", but when I enter the input name in my Php code it does not receive the data. Follow the code I’m using is 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);
?>
However it does not receive the data from Inputs, I know it may seem obvious but I could not find the solution in the PHP documentation, and I would not like to change the name of the Inputs because I have the javascript validation codes and the stylesheet written in this format
php shows some error or just the data in the database is blank?? I noticed that the quotes and the dot and comma are missing at the end of your sql code.
– João Victor Souza
After receiving the data in php try a
var_dump($_POST);
and post here so we can see if you’re receiving the data or not.– João Victor Souza
Simple debug. At the beginning of the php file, right after the opening tag put the var_dump quoted by @Joãovictorsouza
– Pedro Augusto
Juliano, if you put it like this in HTML:
<input name="data['Curriculo']['rg']" type="text"
, with simple quotation marks? In PHP, this is how:$data["Curriculo"]["name"] = $_POST['$data[Curriculo][name]'];
– Rodrigo Tognin
Why not simplify and
<input name="curriculo_rg" type="text"
? In PHP$_POST['curriculo_rg'];
– Pedro Augusto
After I add the var_dump($_POST);, it displays the message that is receiving the data :Connected successfullyarray(2) { ["_method"]=> string(4) "POST" ["data"]=> array(2) { ["Curriculum"]=> array(62) { ["name"]=> string(18) "Juliano corolesqui" ["rg"]=> string(8) "58558507" ["Cpf"]=> string(14) "082.384.288-81"} } New record successfully created Why in the database save the following data in the fields Array[name] Array[rg] Array[Cpf] 0000-00-00
– Juliano Corolesqui
try $_POST['data']['Resume']['name']
– Pedro Augusto
your code is with several syntax errors.
– Gabriel Carvalho