I am generating a list of images and looking to insert a specific image based on wether or not a submit button has been pressed alongside my image.
Here is my code to generate a list of images. Alongside the images is the submit button, like count and other data:
// Display results
foreach ($media->data as $data) {
echo "<a href=\"{$data->link}\"</a>";
echo "<h4>Photo by: {$data->user->username}</h6>";
echo $pictureImage = "<img src=\"{$data->images->thumbnail->url}\">";
echo "<h5>Like Count for Photo: {$data->likes->count}</h5>";
echo "<form>";
echo '<input type="submit" onClick=post()>';
echo "</form>";
}
I am then trying to insert that picture into my database:
InstagramImages(DB) - image(field)
function post() {
$hostname = "redacted";
$username = "redacted";
$dbname = "redacted";
//These variable values need to be changed by you before deploying
$password = "redacted";
$usertable = "InstagramImages";
//Connecting to your database
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
$sql="INSERT INTO $usertable (image) VALUES ('$pictureImage')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
}
Any help would be appreciated. I need help creating the right INSERT query for the php variable $pictureImage.