我有一個航班表,我正在使用一個循環打印出航班信息以及提交按鈕,點擊的按鈕是數據已提交,因此這是行不通的最好方法。它知道被點擊了什麼按鈕,但不執行SQL的數據插入到我的購物籃如何使用PHP和SQL將表數據提交到另一個表
<?php
$dbQuery=$db->prepare("select * from flights");
$dbQuery->execute();
$index = 1;
while ($dbRow=$dbQuery->fetch(PDO::FETCH_NUM)) {
echo "<div>".
"<div class=\"col-md-3 col-sm-6 hero-feature\">".
"<div class=\"thumbnail\">".
"<img src=\"img/aeroplane.png\" alt=\"\">".
"<div class=\"caption\">".
"<h3>$dbRow[1] to $dbRow[2]</h3>".
"<p>£$dbRow[3]</p>".
"<p>".
"<form method=\"post\" action=\"\">".
"<input type=\"hidden\" name=\"action\" value=\"submit\" />".
"<input type=\"submit\" class=\"btn btn-primary\" id=\"$index-submit\"type=\"submit\" name=\"submit\" value=\"$index\">".
"</form>".
"</p>".
"</div>".
"</div>".
"</div>".
"</div>";
if(isset($_POST['action'])){
//echo '<br />The ' . $_POST['submit'] . ' submit button was pressed<br />';
$dbQuery=$db->prepare("insert into basket values (null, :userID, :flightTo to :flightFrom, :flightPrice, 'N')");
$dbParams = array('userID'=>$userID,'fightTo'=>$dbRow[1],'fightFrom'=>$dbRow[2],'flightPrice'=>$dbRow[3]);
$dbQuery->execute($dbParams);
}
$index++;
}
放後的操作代碼退出循環 –
的身邊,我試過,有現在,但它仍然是不及格的sql語句正確的dbRow的航班名稱和價格,所以我可以插入到我的數據庫 –