PHP does not publish data in Mysql table

Asked

Viewed 42 times

0

Hello!

I’m a beginner in PHP, I’m trying to build an HTML form that should use a PHP code to send the data to a Mysql table.

It turns out that PHP code just doesn’t do anything... doesn’t publish the data and returns no error...

Could someone help me by indicating what I might be doing wrong? I will be very grateful!

Below is the PHP code:

<?php
ini_set('default_charset','UTF-8');
$con=mysqli_connect("url","user","pass", "db_name");
mysqli_set_charset($con,"utf8");

if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

  $name = nl2br(htmlentities($_POST['nome'], ENT_QUOTES, 'UTF-8'));
  $rua = nl2br(htmlentities($_POST['rua'], ENT_QUOTES, 'UTF-8'));
  $numero = nl2br(htmlentities($_POST['numero'], ENT_QUOTES, 'UTF-8'));
  $bairro = nl2br(htmlentities($_POST['bairro'], ENT_QUOTES, 'UTF-8'));
  $cidade = nl2br(htmlentities($_POST['cidade'], ENT_QUOTES, 'UTF-8'));
  $telefone = nl2br(htmlentities($_POST['telefone'], ENT_QUOTES, 'UTF-8'));
  $nascimento = nl2br(htmlentities($_POST['nascimento'], ENT_QUOTES, 'UTF-8'));
  $email = nl2br(htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8'));
  $deficiencia = nl2br(htmlentities($_POST['deficiencia'], ENT_QUOTES, 'UTF-8'));
  $deficienciasim = nl2br(htmlentities($_POST['deficienciasim'], ENT_QUOTES, 'UTF-8'));
  $escolaridade = nl2br(htmlentities($_POST['escolaridade'], ENT_QUOTES, 'UTF-8'));
  $formado = nl2br(htmlentities($_POST['formado'], ENT_QUOTES, 'UTF-8'));
  $sexo = nl2br(htmlentities($_POST['sexo'], ENT_QUOTES, 'UTF-8'));
  $estadocivil = nl2br(htmlentities($_POST['estadocivil'], ENT_QUOTES, 'UTF-8'));
  $filhos = nl2br(htmlentities($_POST['filhos'], ENT_QUOTES, 'UTF-8'));
  $habilitacao = nl2br(htmlentities($_POST['habilitacao'], ENT_QUOTES, 'UTF-8'));
  $possuiveiculo = nl2br(htmlentities($_POST['possuiveiculo'], ENT_QUOTES, 'UTF-8'));
  $situacaoatual = nl2br(htmlentities($_POST['situacaoatual'], ENT_QUOTES, 'UTF-8'));
  $pretensaosalarial = nl2br(htmlentities($_POST['pretensaosalarial'], ENT_QUOTES, 'UTF-8'));
  $regime = nl2br(htmlentities($_POST['regime'], ENT_QUOTES, 'UTF-8'));
  $podeviajar = nl2br(htmlentities($_POST['podeviajar'], ENT_QUOTES, 'UTF-8'));
  $conhecimentosespecificos = nl2br(htmlentities($_POST['conhecimentosespecificos'], ENT_QUOTES, 'UTF-8'));
  $falesobrevoce = nl2br(htmlentities($_POST['falesobrevoce'], ENT_QUOTES, 'UTF-8'));

  $conhecimentos = mysql_real_escape_string($conhecimentosespecificos);
  $falesobre = mysql_real_escape_string($falesobrevoce);

  $areadepreferencia = array();
  $area=implode(', ', $_POST['areadepreferencia']);

$result = mysqli_query($con,"INSERT INTO moderacurriculovesp (nome, rua, numero, bairro, cidade, telefone, nascimento, email, deficiencia, deficienciasim, escolaridade, formado, sexo, estadocivil, filhos, habilitacao, possuiveiculo, situacaoatual, areadepreferencia, pretensaosalarial, regime, podeviajar, conhecimentosespecificos, falesobrevoce) VALUES ('$name', '$rua', '$numero', '$bairro', '$cidade', '$telefone', '$nascimento', '$email', '$deficiencia', '$deficienciasim', '$escolaridade', '$formado', '$sexo', '$estadocivil', '$filhos', '$habilitacao', '$possuiveiculo', '$situacaoatual', '$area', '$pretensaosalarial', '$regime', '$podeviajar', '$conhecimentos', '$falesobre')");

// ENVIA EMAIL
$to      = '[email protected]';
$subject = 'Assunto do email';
$message = 'Corpo do email';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

//

header('Location: mensagem_enviada.html');

?>

Thank you very much!

  • Did you install apache? to start a review test header(loca...)

  • installed yes... even I already have other data, a page, other PHP codes on this same server... everything working well.

  • Enable php to show errors.

  • when you run this code the screen goes blank? puts this at the beginning of the script ini_set('display_errors', true); error_reporting(E_ALL);

1 answer

0

Worked!

The problem was this, on the lines:

$conhecimentos = mysql_real_escape_string($conhecimentosespecificos);
$falesobre = mysql_real_escape_string($falesobrevoce);

I used "mysql" instead of "mysqli"...

By enabling errors as indicated by @rray it was possible to find out!

Thank you very much to everyone who helped!

Browser other questions tagged

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