Enter value of a radio button in the database

0

I have:

<label class="">
      <input name="user_perfil" type="radio" value="administrador">  Administrador
    </label>
    <label class="">
      <input name="user_perfil" type="radio" value="cliente">  Cliente
    </label>

And in my database I have a column:
enum('administrador', 'cliente', 'suporte_tecnico')

I'm getting the POST that contains the value of the radio button:
$perfil = $_POST['user_perfil'];

And I'm calling a function:

function novoUsuario($conexao, $user, $password, $email, $nome, $perfil)
{
   $query = "INSERT INTO usuarios (user_name, user_password_hash, user_email,     user_fullname, rank)
            VALUES ('{$user}', '{$user_password_hash}', '{$email}', '{$nome}', '{$perfil}')";
            return mysqli_query($conexao, $query);
}

But my rank is not being saved in my bank. I'll use this rank to open specific pages for each value (adm, support, etc).

What am I doing wrong to my friends?

    
asked by anonymous 27.04.2016 / 04:18

1 answer

0

Caesar, it seems that you are doing everything right. I did not find any errors. I'm understanding that only the value of $perfil is not being inserted into mysql. I suggest doing a debug.

  • Let's see if you're getting the value of the variable correctly.
  • We will test the insertion in the database with any value.
  • After these results we can determine where the error is.

    Use echo "variável=>".$_POST['user_perfil']; If you see the value in the browser, the recovery of the radio value is ok. If not, the value is not being retrieved correctly.

    Next in the next line use $perfil = "teste"; If you do not see the test value in your database table, this is because the problem lies with the insertion. If you see test in your database table the problem is in the previous stage.

    Another thing. Review the size of the varchar (?) in the creation of the table.

    For you to check the error in your insertion I advise you to use the MysqLi error handler Adapt this code to your function if you have not already done so:

    if (!mysqli_query($con,"INSERT INTO .... "))
      {
         echo("Erro: " . mysqli_error($con));
      }
    
        
    27.04.2016 / 13:50