I have a wierd problem with my script that is suppose to insert the web page's source code into the database.
This script works fine when I'm fetching tiny html page on same server where this code is but when I try to fetch some other page over the internet it just won't work and it doesn't give any errors.
My own thought was that MySQL query runs before the web page is assigned to the $content variable? Is there any way to go around this?
// Set web page to fetch
$url = "http://www.webpage.com";
// Assign web page souce to variable
$content = utf8_decode(htmlspecialchars(file_get_contents($url)));
// Standard MySQL connection
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Insert web page source to database
mysqli_query($con, "INSERT INTO table_name (content) VALUES ('$content')");
//Close connection
mysqli_close($con);