Have what's probably an easy question. I'm trying to move my images into a database, with all the images currently hosted remotely on another server. The script below runs a query where it selects the url address to each image (ie: http://mydomain.com/product.jpg) and then loads it, and inserts it into the table.
This works absolutely perfectly. The problem is I need to be able to insert the model, and other cells at the same time and for the life of me I can't get it to work, so I'm guessing someone here will be able to do this easily.
Here's the sample working code without the additional variables:
<?php
$dbname = "database";
$connection = @mysql_connect("localhost", "username", "password") or die("Couldn't Connect.");
$db = @mysql_select_db($dbname, $connection) or die("Couldn't Select Database.");
$sql = "SELECT * FROM products";
$result = @mysql_query($sql,$connection) or die("Couldn't insert query");
while ($row = mysql_fetch_array($result)) {
$photo = ($row['imagelg']);
$image = file_get_contents($photo);
$table = "product_images";
$query = sprintf("INSERT INTO $table (image) VALUES ('%s')",
mysql_real_escape_string($image, $connection));
$result = mysql_query($query, $connection);
}
?>
Here's what I have which doesn't work:
<?php
$dbname = "database";
$connection = @mysql_connect("localhost", "username", "password") or die("Couldn't Connect.");
$db = @mysql_select_db($dbname, $connection) or die("Couldn't Select Database.");
$sql = "SELECT * FROM products";
$result = @mysql_query($sql,$connection) or die("Couldn't insert query");
while ($row = mysql_fetch_array($result)) {
$photo = ($row['imagelg']);
$name = ($row['name']);
$image = file_get_contents($photo);
$table = "product_images";
$query = sprintf("INSERT INTO $table (image, name) VALUES ('%s','$name')",
mysql_real_escape_string($image, $connection));
$result = mysql_query($query, $connection);
}
?>
Thanks in advance for the person who can point me in the right direction 🆒