Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
PHP - Insert variables in double quote strings

I'm new here. I started PHP recently and I am wondering how I could insert variables, and put them into single quotes, into a double quotes string. Here's what I tried : $query = "INSERT INTO Table (Name, Activity) VALUES ('$name', '$activity');"; But when I check $query, it contains that : INSERT INTO Table (Name, Activity) VALUES (,);. I don't understand why it does that because when, instead of writing the above code, I write this one : $query = "INSERT INTO Table (Name, Activity) VALUES ($name, $activity);"; (without the single quotes), the string contains this : INSERT INTO Table (Name, Activity) VALUES (Robert, Book-seller);. Does anybody have a clue ?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

how I could insert variables, and put them into single quotes, into a double quotes string.

Don't do that. It leaves you vulnerable to SQL injection attacks. Instead use prepared statements with bound parameters as described in this post.

over 4 years ago · Santiago Trujillo Relatório

0

I tried your statement:

$query = "INSERT INTO Table (Name, Activity) VALUES ('$name', '$activity');";

And It worked perfectly with me. I guess you need to check the values you passing in $name and $activity. (for Robert, Book-Seller its working nicely).

Still You may try this. It might help:

$query = "INSERT INTO Table (Name, Activity) VALUES (\"$name\", \"$activity\");";

And a note for caution: as Alex Howansky says, don't do that. it leaves you vulnerable to SQL injection attacks.

Hope it helps. All the best!

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda