Problem when saving record in database with PHP7


I am using PHP 7 to enter records in a database. It says "full subscription" but I check my database and I do not have any data saved. Where this error? And how can I solve it?

This is my registry.php file

$db_connection = mysqli_connect($db_host, $db_user, $db_password, $db_name);

if (!$db_connection) {
    die('No se ha podido conectar a la base de datos');
$subs_name = utf8_decode($_POST['nombre']);
$subs_last = utf8_decode($_POST['apellido']);
$subs_email = utf8_decode($_POST['email']);

$resultado = mysqli_query($db_connection, "SELECT * FROM Nuevo");

if (mysqli_num_rows($resultado)>0)

header('Location: Fail.html');

} else {

    $insert_value = "INSERT INTO Nuevo (Nombre, Apellido, email) values ('$_POSTname[nombre]','$_POST[apellido]','$_POST[email]')";

$retry_value = mysqli_query($db_connection, $insert_value);

if (!$retry_value) {
   //die('Error: '.mysqli_error());

header('Location: success.html');




And this is my index.html

<!doctype html>
<meta charset="utf-8">
<title>Formulario de Registro SCIII</title>
<link href="estilos.css" rel="stylesheet" type="text/css">


<div class="group">
  <form action="registro.php" method="POST" action="registro.php">
  <h2><em>Formulario de Registro</em></h2>

      <label for="nombre">Nombre <span><em>(requerido)</em></span></label>
      <input type="text" id="nombre" name="nombre" class="form-input" required/>   

      <label for="apellido">Apellido <span><em>(requerido)</em></span></label>
      <input type="text" id="apellido" name="apellido" class="form-input" required/>           

      <label for="email">Email <span><em>(requerido)</em></span></label>
      <input type="email" id="email" name="email" class="form-input" />

     <center> <input class="form-btn" name="submit" type="submit" value="Suscribirse" /></center>
asked by manuel dacambra 22.07.2016 в 22:19

2 answers


You have an error in insert that will make it fail:

INSERT INTO Nuevo (Nombre, Apellido, email) values ('$_POSTname[nombre]','$_POST[apellido]','$_POST[email]')

If you notice it puts $_POSTname[nombre] and that is incorrect, it should be $_POST[nombre] .

INSERT INTO Nuevo (Nombre, Apellido, email) values ('$_POST[nombre]','$_POST[apellido]','$_POST[email]')

Apart from that, your code may suffer SQL injection attacks , you should use prepared statements instead of SQL dynamic.

answered by 22.07.2016 в 22:30

I recommend you declare a variable to save the name and other data, so you can apply some kind of filter and use the isset function to not try to enter empty variables

$v_nombre =isset( $_POST['nombre'])?strip_tags($_POST['nombre']):'no-ingresa';

for example, and then make the query with the variable

$insert_value = "INSERT INTO Nuevo (Nombre, Apellido, email) values ('$v_nombre','$v_apellido','$v_email')";
answered by 27.07.2016 в 22:00