Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

153
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda