0
我目前有一個while循環運行通過一個數據庫選擇數據罰款,其中一列我顯示的圖像點擊時,我想插入數據到不同的數據庫。使用while循環插入數據到我的數據庫
用於插入數據的if語句是;
if (isset($_POST['acceptloan'])):
$username=$_POST['username'];
$product=$_POST['product'];
$start_loan=$_POST['start_loan'];
$return_loan=$_POST['return_loan'];
$my_iquery="INSERT INTO loans VALUES ('','$username','$product','','','$start_loan','$return_loan','No')";
$iresult= mysqli_query($connection, $my_iquery);
if ($iresult):
header ('location: homepage.php?confirm=Loan Accepted');
else :
echo "<b>This didn`t work, error: </b>";
echo mysqli_error($connection);
endif;
endif;
我測試了這個,它的工作原理但我不知道如何讓我的PHP從我的while循環運行它。
我的循環是;
while ($myrow = mysqli_fetch_array($result)):
$requestid = $myrow["requestid"];
$username = $myrow["username"];
$product = $myrow["product"];
$start_loan = $myrow["start_loan"];
$return_loan = $myrow["return_loan"];
$table = '<tr>';
$table.= '<td>'.$requestid.'';
$table.= '<td>'.$username.'';
$table.= '<td>'.$product.'';
$table.= '<td>'.$start_loan.'';
$table.= '<td>'.$return_loan.'';
$table.= "<td align='center'><a onClick =\"return confirm('Are You Sure You Want To Accept This Request?')\" href=acceptrequest.php?requestid=$requestid><img src=\"tick2.png\">";
$table.= "<td><a onClick =\"return confirm('Are You Sure You Want To Reject this Request?')\" href=deleterequest.php?requestid=$requestid><img src=\"delete.png\">";
echo $table;
endwhile;
im引用的代碼是接受請求行 - 我將如何指向代碼以執行IF語句?
感謝
你的while循環獲取數據,而不是插入。請更清楚一點,你試圖實現什麼 – e4c5
@ e4c5 im知道我的while循環正在獲取數據,這是它應該做的。在循環內,它將tick2.png圖像放在特定列的每一行上。當圖像被按下時,我想要執行If語句,以便將當前行中的所有數據插入'loans'數據庫 – Mucca019
,這使得事情變得更清晰,仍然很模糊。如果我理解正確,你需要投資Ajax – e4c5