保存它的 PHP 代码。
$cols = $_POST['col'];
$EvenementID = mysql_real_escape_string($_POST['evenementid']);
foreach($cols as $col) {
$Ticketnaam = mysql_real_escape_string($col['ticket']);
$Aantal = mysql_real_escape_string($col['aantal']);
$Prijs = mysql_real_escape_string($col['prijs']);
$sql = "INSERT INTO tbl_Tickets (EvenementID, Ticketnaam, Aantal, Prijs) VALUES('".$EvenementID ."', '{$Ticketnaam}', '{$Aantal}', '{$Prijs}')";
}
代码
<input type="hidden" name="evenementid" value="<?php echo $evenementid; ?>" />
区块 1
<input type="text" name="col[0][ticket]" id="ticket" class="tekst-lang"/>
<input type="text" class="tekst-lang" name="col[0][aantal]" id="aantal"/>
<input type="text" class="tekst-lang" name="col[0][prijs]" id="prijs"/>
区块 2
<input type="text" name="col[1][ticket]" id="ticket" class="tekst-lang"/>
<input type="text" class="tekst-lang" name="col[1][aantal]" id="aantal"/>
<input type="text" class="tekst-lang" name="col[1][prijs]" id="prijs"/>
AJAX
var myData = $('#ticket-form').serialize();
$.ajax({
type: "POST",
//URL of the php file that will process the login
url: "includes/ticket.php",
dataType: 'json',
//Pass the data through
data: myData,
//Handle the response
success: function (data) {
switch(data.case){
case 1:
$(".inlog-feedback").html(data.message).fadeIn('slow');
break;
case 2:
$(".inlog-feedback").html(data.message).fadeIn('slow');
window.location = "index.php";
break;
case 3:
$(".inlog-feedback").html(data.message).fadeIn('slow');
break;
default:
/* If none of the above */
}
}
})
//Stop the submit button from submitting the form
return false;
}
我正在尝试将 2 个块保存到我的数据库中(所以我需要 2 条记录)。两个块具有相同的evenementID。问题是数据库中只有一条记录。