Why my query is not working with the php variable

0

I'm having problems with my mysql query . The value is passed from the php form correctly with $_POST , however when I add the variable to make the comparison the query does not send a response, but if I add the exact value that is in the database I get a response, but I need to use the value which comes from the variable.

This work works

//pegar matricula
  $query_matricula = mysqli_query($conexao,"SELECT matricula FROM usuario where nome = 'Maria'") or die("ERROR" .mysqli_error());
  $row = mysqli_fetch_assoc($query_matricula);
  $numero_matricula = $row['matricula'];
  echo $row['matricula'];

That way it does not work

 //pegar matricula
  $query_matricula = mysqli_query($conexao,"SELECT matricula FROM usuario where nome = '$nome'") or die("ERROR" .mysqli_error());
  $row = mysqli_fetch_assoc($query_matricula);
  $numero_matricula = $row['matricula'];
  echo $row['matricula'];
    
asked by anonymous 10.12.2015 / 13:40

2 answers

1

Make sure that what comes from the post is the same as the content you're looking for. I like to do this ... echo '-'.$nome.'-'; . It may have spaces in the name. Clean them: $nome = trim( $_POST[ 'nome' ] ); .

    
10.12.2015 / 14:01
-1

try this way

$query_matricula = mysqli_query($conexao,"SELECT matricula FROM usuario where nome = '{$nome}'") or die("ERROR" .mysqli_error());
    
11.12.2015 / 19:08