Home > Back-end >  How to add ' ' to php variable in query
How to add ' ' to php variable in query

Time:07-08

Hello i have this simple query

$query = "SELECT id FROM `client` where name= ".$user_name;

Now the query is printed

select id from client where name = Bob;

when in fact it should be

select id from client where name = 'Bob';

how can i add single quotes in the php variable?

CodePudding user response:

I warned you and you are fine to sql injection then just try this.

$query = "SELECT id FROM `client` where name= '".$user_name."'";
  • Related