我正在生成一個圖像列表,希望插入一個特定的圖像根據是否提交按鈕已被按下我的形象。MYSQL插入提交按鈕PHP
這是我的代碼來生成圖像列表。除了圖像是提交按鈕,像數和其他數據:
// 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查詢。
呃..你有什麼問題或錯誤? – Anil
@JustAnil對不起,請參閱編輯。 – qweqweqwe
作爲你的html建議由foreach循環生成,在同一個頁面中會有多個同名的提交按鈕,具有相同的函數調用post();所以你必須通過傳遞一些唯一的id參數來確定哪個提交按鈕被按下, – developerCK