我目前正在创建一个应用程序,该应用程序获取 instagram 图像列表,然后将某些图像(根据您的选择)插入特定数据库。
目前,当我选择提交按钮时,它会抓取列表中最后一个可用的图像并将其插入到我的数据库中。每个图像都分配有一个提交按钮。如何确保与提交按钮相关的正确图像是插入数据库的图像。
以下是我的图像列表代码和每个图像的提交按钮:
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>";
}
这就是我将图像插入数据库的方式。请记住,这会抓取列表中最后一个可用的图像并将其插入。
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);
}
有什么建议么?