我知道如何正常發送這個表單,並且需要定期提交。然而,我對如何通過.ajax發送多維表單數組感到困惑。通過.ajax發送多維表單數組到PHP準備語句
我的形式:
<form action="week_update.php" id="theform" method="post">
<input type="text" name="data[][wednesday_crew]" value=""/>
<input type="text" name="data[][thursday_crew]" value=""/>
<input type="text" name="data[][friday_crew]" value=""/>
<input type="text" name="data[][saturday_crew]" value=""/>
<input type="text" name="data[][sunday_crew]" value=""/>
我的PHP:
$stmt = $connection->stmt_init();
if($stmt->prepare("UPDATE tableName SET ... = ?, ... = ?,)) {
// Bind your variables
$stmt->bind_param('ss', $.., $..,);
// get the multi array from form
$returnedData = $_POST['data'];
//let's loop through it.
for($i=0;$i<count($returnedData);$i+=2){
$log_dates_ID = $returnedData[$i]['...'];
$crew_chief = $returnedData[$i+1]['...'];
$stmt->execute();
}
謝謝!在服務器端呢? – user1040259
服務器端 - 如您所說,您的示例中的php有效。因爲這種情況下,將代碼放在一個'path/to/your/script.php'文件中,它將在表單提交中執行。 – Vector
表單正在提交,但數據未被插入到我的數據庫中。任何其他快速的想法?再次感謝! – user1040259