database – How to insert a variable into an array?

Question:

I want to insert data into my database I'm using mysqli, I need to know how to indicate a variable inside an array, here and my code I want to know if this is the correct way to do this

require 'config.php'
require 'connection.php'

$nomearquivo ="teste.html";
$nome =$_POST["nome"];
$sexo =$_POST["sexo"];
$dia  =$_POST["dia"];
$mes  =$_POST["mes"];
$ano  =$_POST["ano"];
$abre =@fopen("dadosss.html","a+");
$ess  ="nome: " .$nome. " sexo: " .$sexo." ".$dia."/".$mes."/".$ano;
$escreve =fwrite($abre, $ess );

$inserir = array(
    'nome' => $nome, 
    'sexo' => $sexo,
    'dia'  => $dia,
    'mes'  => $mes,
    'ano'  => $ano,

);

$grava = DBCreate('cadastro', $inserir);

if($grava)
    echo 'OK';

Answer:

You can use array_push to solve the problem.

Scroll to Top
AllEscort