I’m getting json data from a website.. but in the data there is single quote that causing the problem. what will you suggest me to do i already tried str_replace is not working please help
Here is code
$string=file_get_contents('http://website');
$string=str_replace("'", "\'", $string);//not working
$json=json_decode($string);
foreach($json as $p)
{
$query="INSERT INTO abc(id,
name,
address,
address2,
storeID,
) VALUES('$p->id',
'$p->name',
'$p->address',
'$p->address2',
'$p->storeID',
)";
mysql_query($query) or die(mysql_error());
}
if I use str_replace this error comes
Warning: Invalid argument supplied for foreach()
You’re replacing a single quote with a single quote. Instead, you want:
Also, you must not insert user input into SQL statements. Either use prepared statements or encode the user input.