Parameterized query php output

1

Modifying my school codes to add parameters, because I do not understand the php documentation and I do not know how to get the result of the query. From the privilege table should give 1 (administrator) or 2 (secretary). Help please.

  try {

      //Conection papu
      $cnn = mysqli_connect("localhost", "root", "", "dbautomotora");

      if (!$cnn) {
        die("Conexion Fallida: " . mysqli_connect_error());
      }else {
        $nombre_usuario = $_POST['txt_nombre_admin']; //Nombre del usuario
        $contraseña_usuario = $_POST['txt_password_admin'];//Contraseña usuario
        $privilegio_usuario = $_POST['sel_privilegio']; //Nivel del usuario

        $sql = mysqli_prepare($cnn,"SELECT privilegio FROM usuarios WHERE (nombre = ? and password = ? and privilegio = ?)");
        mysqli_stmt_bind_param($sql, "ssi", $nombre_usuario, $contraseña_usuario, $privilegio_usuario);

        $rs = mysqli_stmt_execute($sql);
          //PARAMETRIZADO HASTA AQUI
        if ($rs==0) {
          //No hay dato vuelve a la pagina
        }else {
              while ($fila = mysqli_stmt_fetch($sql)) {
                  $nivel = $fila["privilegio"];
                  echo $nivel; //Quiero que me devuelva la consulta como se hace help
              }


          }
      }
    } catch (\Exception $e) {
      //Errores de excepcion
    }
    
asked by Sebastian Ismael 27.11.2018 в 03:45
source

1 answer

1

I answer alone, it is very noob the question so if they tell me I delete it. the function mysqli_stmt_bind_result($consulta,$variable) allows linking a variable by fila(?) of the result of while , from there you can save them and manipulate them at ease.

if ($rs==0) {
      //No hay dato vuelve a la pagina
    }else {
        mysqli_stmt_bind_result($sql, $privilegio); 
          while ($fila = mysqli_stmt_fetch($sql)) {
              printf($privilegio);

          }


    }
  }
    
answered by 27.11.2018 в 04:21