我正在生成一个图像列表,并希望根据我的图像旁边是否按下提交按钮来插入特定图像。
这是我生成图像列表的代码。图片旁边是提交按钮,如计数和其他数据:
// 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>";
}
然后我试图将该图片插入到我的数据库中:
InstagramImages(DB) - 图像(字段)
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);
}
任何帮助,将不胜感激。我需要帮助为 php 变量 $pictureImage 创建正确的 INSERT 查询。