Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. How to insert roles in php and mysql?

How to insert roles in php and mysql?

Scheduled Pinned Locked Moved Web Development
databasephpmysqltutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nicolas Veloso
    wrote on last edited by
    #1

    Hello good, I have a query, what happens is that I want to enter user roles in my code but I don't know how to do it, I have the registration and login form already created, I just need to add the reference that I already mentioned above: register_user_be.php:

    1. {
      echo '
      alert("Este correo ya está registrado");
      window.location = "../index.php";
      ';
      exit();
      }

    //Verificar que el nombre de usuario no se repita en la bd

    $verificar_usuario = mysqli_query($conexion, "SELECT * FROM usuarios WHERE usuario='$usuario' ");
    if (mysqli_num_rows($verificar_usuario) > 0) {
    echo '
    alert("Este usuario ya está registrado");
    window.location = "../index.php";
    ';
    exit();
    }

    $ejecutar = mysqli_query($conexion, $query);
    if ($ejecutar) {
    echo '
    alert("Usuario registrado correctamente");
    window.location = "../index.php";
    ';
    }else{
    echo '
    alert("Inténtalo de nuevo, usuario no registrado");
    window.location = "../index.php";
    ';
    }

    mysqli_close($conexion);

    ?>

    login_usuario_be.php:

    1. {
      $_SESSION['usuario'] = $correo;
      header("location: ../inicio.php");
      exit;
      }else{
      echo '
      alert("El usuario no existe, por favor verifique los datos introducidos");
      window.location = "../index.php";
      ';
      exit;
      }

    ?>

    index.php:

    Richard DeemingR M 2 Replies Last reply
    0
    • N Nicolas Veloso

      Hello good, I have a query, what happens is that I want to enter user roles in my code but I don't know how to do it, I have the registration and login form already created, I just need to add the reference that I already mentioned above: register_user_be.php:

      1. {
        echo '
        alert("Este correo ya está registrado");
        window.location = "../index.php";
        ';
        exit();
        }

      //Verificar que el nombre de usuario no se repita en la bd

      $verificar_usuario = mysqli_query($conexion, "SELECT * FROM usuarios WHERE usuario='$usuario' ");
      if (mysqli_num_rows($verificar_usuario) > 0) {
      echo '
      alert("Este usuario ya está registrado");
      window.location = "../index.php";
      ';
      exit();
      }

      $ejecutar = mysqli_query($conexion, $query);
      if ($ejecutar) {
      echo '
      alert("Usuario registrado correctamente");
      window.location = "../index.php";
      ';
      }else{
      echo '
      alert("Inténtalo de nuevo, usuario no registrado");
      window.location = "../index.php";
      ';
      }

      mysqli_close($conexion);

      ?>

      login_usuario_be.php:

      1. {
        $_SESSION['usuario'] = $correo;
        header("location: ../inicio.php");
        exit;
        }else{
        echo '
        alert("El usuario no existe, por favor verifique los datos introducidos");
        window.location = "../index.php";
        ';
        exit;
        }

      ?>

      index.php:

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query. PHP: SQL Injection - Manual[^] PHP: Prepared statements and stored procedures - Manual[^] You are also storing an unsalted hash of the user's password. That's not secure enough - your database will be vulnerable to a "rainbow table" attack. Rainbow table - Wikipedia[^] Use PHP's built-in functions for storing and validating passwords: PHP: password_hash[^] PHP: password_verify[^] These will automatically take care of generating and storing a random salt for you.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • N Nicolas Veloso

        Hello good, I have a query, what happens is that I want to enter user roles in my code but I don't know how to do it, I have the registration and login form already created, I just need to add the reference that I already mentioned above: register_user_be.php:

        1. {
          echo '
          alert("Este correo ya está registrado");
          window.location = "../index.php";
          ';
          exit();
          }

        //Verificar que el nombre de usuario no se repita en la bd

        $verificar_usuario = mysqli_query($conexion, "SELECT * FROM usuarios WHERE usuario='$usuario' ");
        if (mysqli_num_rows($verificar_usuario) > 0) {
        echo '
        alert("Este usuario ya está registrado");
        window.location = "../index.php";
        ';
        exit();
        }

        $ejecutar = mysqli_query($conexion, $query);
        if ($ejecutar) {
        echo '
        alert("Usuario registrado correctamente");
        window.location = "../index.php";
        ';
        }else{
        echo '
        alert("Inténtalo de nuevo, usuario no registrado");
        window.location = "../index.php";
        ';
        }

        mysqli_close($conexion);

        ?>

        login_usuario_be.php:

        1. {
          $_SESSION['usuario'] = $correo;
          header("location: ../inicio.php");
          exit;
          }else{
          echo '
          alert("El usuario no existe, por favor verifique los datos introducidos");
          window.location = "../index.php";
          ';
          exit;
          }

        ?>

        index.php:

        M Offline
        M Offline
        Member_15005211
        wrote on last edited by
        #3

        Create The Best Website Now. Powerful eCommerce Tools. Responsive Website Design. Website Localization. Build In Under 1 Day. 24/7 Free Support. Visit us: IT SOLUTIONS

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups