<?php
for ($i = 1; $i <= 5; $i++) {
$name = 'name' . $i;
$id = 'id' . $i;
echo '<form method="POST" action="" name = "' . $name . '" id = "' . $id . '">';
echo'<input type="number" name="roll" id="roll" placeholder="Enter Roll"><br>' .
'<input type="text" name="name" id="name" placeholder="Enter Name"><br>' .
'<input type="text" name="address" id="address" placeholder="Enter Address"><br>' .
'<button type="button" onclick="submitdata(this);"> Submit </button><br>';
echo '</form><br>';
}
?>
这是php代码。我在php echo标记中插入表单。我使用mysql数据库。
function submitdata() {
var roll = document.getElementById("roll").value;
var name = document.getElementById("name").value;
var address = document.getElementById("address").value;
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'roll=' + roll + '&name=' + name + '&address=' + address;
if (roll == '' || name == '' || address == '') {
alert("Please Fill All Fields");
} else {
// AJAX code to submit form.
$.ajax({
type: "POST",
url: "submit.php",
data: dataString,
cache: false,
success: function (html) {
alert(html);
}
});
}
return false;
}
这是我的javascript代码。请帮我提个建议。如何从php循环插入表单数据?
暂无答案!
目前还没有任何答案,快来回答吧!