This question already has an answer here:
- Can I mix MySQL APIs in PHP? 4 answers
- How can I prevent SQL injection in PHP? 28 answers
Hey i have problem with php insert from json data to mysql all works fine when $idd = $row['id'];
id looks like WJWJj24ijiJSI5 but sometimes can be like JWk---rwk@o and then i get error because it's use !@#$%^&*(- need to fix it
Error : You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'misery." WHAT IT DO BABY BOO. this my world. my crazy life. my stories, my tear' at line 1
$url = 'hiddenURL';
$content = file_get_contents($url);
$json = json_decode($content, true);
foreach($json as $row);
foreach($json['items'] as $row)
{
$idd = $row['id'];
$title = $row['snippet']['title'];
$description = $row['snippet']['description'];
$viewCount = $row['statistics']['viewCount'];
$subscriberCount = $row['statistics']['subscriberCount'];
$sql = "INSERT INTO vartotojai(idd, title, description, viewCount, subscriberCount) VALUES('$idd', '$title','$description','$viewCount','$subscriberCount')
ON DUPLICATE KEY UPDATE idd='$idd', title='$title', description='$description', viewCount='$viewCount', subscriberCount='$subscriberCount';
";
mysqli_query($conn, "SET NAMES utf8");
if(!mysqli_query($conn,$sql))
{
die('Error : ' . mysqli_error($conn));
}
}
$conn->close();
</div>