Mysql Query does not work with many arguments

Asked

Viewed 224 times

0

I would like to request assistance from you identifying why my update query does not work. I have the following problem, the query below works normally:

$conn->query("UPDATE dados_cadastrais SET 
nome='$nome',sobrenome='$sobrenome',nascimento='$nascimento',cpf='$cpf',cep='$cep',logradouro='$logradouro',bairro='$bairro',localidade='$localidade',uf='$uf',ibge='$ibge',numero='$numero',usuario='$usuario',senha='$senha'")

But there it is without the WHERE clause pointed out, but when I put it, it does not recognize as part of the query the WHERE or anything after it, I’ve tried everything and I can’t find where the error is(if there is any error), or some other way to do it, follows image of how it looks in the text editor (I use Atom):

inserir a descrição da imagem aqui

Thanks in advance for the help, because I’ve researched everything possible and found nothing like my problem.

  • 3

    Never do that again in your life, if a user catches your system or website makes a good SQL Injection. Use PDO to solve your problem with database connection and instead of passing parameters use bindParam() Function. http://php.net/manual/en/pdostatement.bindparam.php

  • yes for sure, you can rest assured that this is only place for study really, but I’ll take a look at this Function and I’ll tell you if it worked, but thanks for now

  • missing put the variable $id between quotation marks as well where id='$id'

  • password='$password' WHERE Id='". $Id."'");

  • in my updates both work

2 answers

0

try to pass as string, using apostrophes
probably why php is ignoring it

$conn->query("UPDATE dados_cadastrais SET 
nome='$nome',
sobrenome='$sobrenome',
nascimento='$nascimento',
cpf='$cpf',
cep='$cep',
logradouro='$logradouro',
bairro='$bairro',
localidade='$localidade',
uf='$uf',
ibge='$ibge',
numero='$numero',
usuario='$usuario',
senha='$senha'
Where id = '$id' ");
  • Opa, worst that still does not work, I tried to concatenate with '". $variavel." ', with "$variable", with '$variable' and does not roll, the interesting thing is that if I take for example the last part password = '$password' it takes the WHERE certinho.

  • sends the return error code and

0

I appreciate the help of all, I tried everything that was shown but what ended up solving was to concatenate the query in 2 lines, I did not understand very well why of this, but it was like this:

inserir a descrição da imagem aqui

Browser other questions tagged

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