Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!