I am currently creating an application that grabs a list of instagram images and then inserts certain ones (based on your choice) into a specific database.
Currently, when I select the submit button it is grabbing the last available image in the list and inserting that into my database. Each image is assigned a submit button. How do I make sure the proper image, relative to the submit button, is the one being inserted into the database.
The following is my code for the list of images and the submit button for each image:
foreach ($media->data as $data) {
echo $pictureImage = "<img src=\"{$data->images->thumbnail->url}\">";
echo "<form action='tag.php' method='post'>";
echo "<input type='submit' name='submit' value='Click Me'>";
echo "</form>";
}
This is how I am inserting the image into my database. Remember, this grabs the last available image in the list and inserts that.
if(isset($_POST['submit'])) {
// There variables are for the database information
$hostname = "random";
$username = "random";
$dbname = "random";
$password = "random!";
$usertable = "random";
//Connecting to your database
$con = mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname, $con);
$sql="INSERT INTO $usertable (image) VALUES ('$pictureImage')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error($con));
}
mysql_close($con);
}
Any suggestions?