Some Java Guy
Some Java Guy

Reputation: 5118

insert single quote before inserting

My php code returns some value, I am trying to insert in database.

$string =  '1,here,Skincare composition against free radicals'; //this is returned

'(insert into import (S.No,Name,Title)) values ($string)'  

Need to convert that string in proper format to insert in db

'1','here','Skincare composition against free radicals'  //This is expected

implode should do it? But I dont know how?

Upvotes: 2

Views: 142

Answers (1)

John Woo
John Woo

Reputation: 263703

try,

$string =  "1,here,Skincare composition against free radicals";
$varList = explode(",", $string);
$newQuery = "INSERT INTO `import` (`S.No`,`Name`,`Title`) VALUES ('" . $varList[0] . "','" . $varList[1] . "','" . $varList[2] . "')";

but the query is vulnerable with SQL Injection, please read the article below to how learn to protect from it,

Other Source

Upvotes: 10

Related Questions