Registration in php

Asked

Viewed 70 times

2

Hello, all good ? , I have a problem in performing data insertion in a MYSQL database. When I type a password in my form, for example: metas123, or any other password, it stores the value 0, instead of the string typed, and I really have no idea why this happens... if you can help me thank you very much.

if (!empty($_POST['user']) and !empty($_POST['pass'])) {

     $g_user = mysqli_real_escape_string($conn, $_POST['user']);
     $g_pass = $_POST['pass'];

     $sql = "INSERT INTO usuarios (usuario, senha) VALUES ('$g_user', '$g_pass');";
     $executa = mysqli_query($conn, $sql);

     switch ($executa) {

       case true:
         header("Location: login_page/index.php?cadastro=sucesso");
         break;

       default:
         header("Location: index.php?cadastro=erro");
         break;

      }
   }

*Insertion code to mysql database

  • 1

    thanks kk, first time I touch the stackoverflow, sorry anything

  • 2

    This question could only be answered if you put the column types of your table and the types of how they are being sent .

  • 1

    What values comes from $_POST ? They are correct ? Test with var_dump($_POST); and confirm that you have the correct values. Then do what Leo said and put the table structure usuarios on the question to make sure that the types are correct.

  • 1

    opa, all good Isac? , admire your attention, but fortunately already solved the problem, the type of the field in the password table was marked as INT.

1 answer

-1

Has a ; remaining there:

$sql = "INSERT INTO usuarios (usuario, senha) VALUES ('$g_user', '$g_pass');";

Replace with:

$sql = "INSERT INTO usuarios (usuario, senha) VALUES ('$g_user', '$g_pass')";

[SOLVED] Field type in table was incorrect

  • 1

    I’ll try here

  • 1

    ah already identified the problem.. thanks, I marked the password field as int kkkkk, but thanks for your attention

  • Show, who I thank for being able to help!

Browser other questions tagged

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