2

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?

John Woo
  • 258,903
  • 69
  • 498
  • 492
Some Java Guy
  • 4,992
  • 19
  • 71
  • 108

1 Answers1

10

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

Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492