Database does not receive / save data from php form


I have this problem and I do not understand where the error could be, when I click on the final submit it does not save anything in the DB. If they need another code fragment or show the BD they tell me.

I hope you can tell me why you are not saving, greetings!

Here is the form I use, by clicking the input submit name="btn_registrar" I should call registro_usuarios.php :

    require_once "funciones/db.php";

<!DOCTYPE html>
<html lang="en" >

  <meta charset="UTF-8">
  <link rel="stylesheet" href="">
  <link rel="stylesheet" href="css/style_formulario.css">

  <div class="gradDynamic">
    <h1 class="color_letra"> Regístrate y sé parte de nuestra comunidad!</h1>
    <!-- multistep form -->
    <form role="form" action="funciones/registro_usuarios.php" id="msform" method="POST">
      <div id="signupalert" style="display:none">
      <!-- progressbar -->
      <ul id="progressbar">
        <li class="active">Creacion Cuenta</li>
        <li>Detalles Personales</li>
        <li>Redes sociales</li>

      <!-- fieldsets -->
        <h2 class="fs-title">Crea tu Cuenta</h2>
        <h3 class="fs-subtitle"> Paso 1</h3>
        <input type="text" name="run" placeholder="Run alumno Inacap" >
        <input type="text"  name="email"  placeholder="E-mail institucional" >
        <input type="password" name="pass" placeholder="Password"  >
        <input type="password" name="cpass" placeholder="Confirmar Password" >
        <input type="button" name="next" class="next action-button" value="Siguiente"  >
        <h2 class="fs-title">Detalles Personales</h2>
        <h3 class="fs-subtitle">Muestrate al mundo!</h3>
        <input type="text" name="nombre" placeholder="Nombre"  >
        <input type="text" name="apellido" placeholder="Apellido" >
        <select class="" name="carrera">
          <option selected disabled hidden>Selecciona Tu Carrera</option>
          <option value="1"> Diseño Web & mobile</option>
          <option value="2"> Diseño Grafico</option>
          <option value="3"> Diseño Profesional</option>
        <textarea name="about" rows="8" cols="80" placeholder=" Describete a ti mismo!"></textarea >
          <input type="button" name="previous" class="previous action-button" value="Anterior"  />
          <input type="button" name="next" class="next action-button" value="Siguiente" />
          <h2 class="fs-title">Redes Sociales</h2>
          <h3 class="fs-subtitle">Tu presencia en las Redes Sociales</h3>
          <input type="text" name="twitter" placeholder="Twitter" >
          <input type="text" name="facebook" placeholder="Facebook">
          <input type="text" name="linkedin" placeholder="Linkedin" >
          <input type="text" name="github" placeholder="Github" >
          <input type="text" name="pinterest" placeholder="Pinterest">
          <input type="text" name="instagram" placeholder="Instagram" >
          <input type="button" name="previous" class="previous action-button" value="Atras" />
          <input type="submit" name="btn_registrar" class="submit action-button" value="Crear" />
      <div class="cuadro">
        <img src="css/titulo.png" width="200" height="100">
    <script src=''></script>
    <script src=''></script>
    <script  src="js/index.js"></script>

Here is the part of the file functions / registro_usuarios.php:

if (isset($_POST['btn_registrar'])){
 include_once 'db.php';

// Guardamos los Post del Registro.php
 $run = mysqli_real_escape_string($link,$_POST['run']);  //mysqli_real_escape_string -- Metodo seguridad, convierte
 $email = mysqli_real_escape_string($link,$_POST['email']);  //a texto dentro de input para prevenir sql inyection !
 $pass =  mysqli_real_escape_string($link,$_POST['pass']);
 $cpass =  mysqli_real_escape_string($link,$_POST['cpass']);
 $nombre =  mysqli_real_escape_string($link,$_POST['nombre']);
 $apellido =  mysqli_real_escape_string($link,$_POST['apellido']);
 $about =  mysqli_real_escape_string($link,$_POST['about']);

//Errores! - Chequeo para campos en blancos!

if(empty($run) || empty($email) || empty($pass) || empty($cpass) || empty($nombre) || empty($apellido) ){
  header("Location: ../registro.php?registro=empty");
} else {
  // Chequeamos si los caracteres del  input  son validos
  if(!preg_match("/^[a-zA-Z]*$/", $nombre) || !preg_match("/^[a-zA-Z]*$/", $apellido) || !preg_match("/^[1-9]*$/", $run) ){
  header("Location: ../registro.php?registro=invalid");

} else { // Chequeamos si email es valido
  if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    header("Location: ../registro.php?registro=email");
  } else{
    $sql = "SELECT * FROM usuario WHERE nombre ='$nombre'";
    $resultado = mysqli_query($link, $sql);
    $resultadoCheck = mysqli_num_rows($resultado);

    if($resultadoCheck > 0){
      header("Location: ../registro.php?registro=nombreRegistrado");
    } else {
      // Hashing la password
      $hashedpass = password_hash($pass, PASSWORD_DEFAULT);

      // Ingresamos al usuario dentro de la database!

      $sql ="INSERT INTO usuario (nombre, apellido, pass, run, email, about) VALUES ('$nombre', '$apellido', '$hashedpass', '$run', '$email', '$about'); ";
      mysqli_query($link, $sql);
      header("Location: ../registro.php?registro=success");


} else {
  header("Location: ../registro.php");

and finally my file functions / db.php:

 function conectar(){
    $servidor = "localhost:3306";
    $usuario = "root";
    $password = "";
    $baseDatos = "valpocrea";
    $link = mysqli_connect($servidor, $usuario, $password, $baseDatos);
return $link;
asked by Bastien Wevar 01.10.2018 в 18:29

2 answers


Try to activate the error report in your functions / registration_users.php script with

error_reporting(E_ALL) ;

and comment the header so you can see the error.

Update the question with the details of the error you got.

answered by 01.10.2018 в 19:00

You do not initialize the connection. Just before the call to mysqli_query put:

$link = conectar();
answered by 01.10.2018 в 22:48