我需要发生以下事情:
A form with multiple input boxes that receives user information.
An "Add User" button that allows for additional user input.
A submit button that will INSERT the data from the form into the designated database column, and creates a new row in the database for each new user.
我很新,不知道如何循环 results.php 页面上的 $_REQUEST
数组来执行此操作。我愿意接受任何建议。预先感谢您。
var fname, lname, dob, input, inputCount = 0;
$(window).load(function() {
newUser();
})
function newUser() {
$('#box >div').hide();
inputCount++;
input = $('<div data-id="' + inputCount + '">Entry ' + inputCount + '<br><br></div>').appendTo('#box');
fname = $('<input type="text" name="fname' + inputCount + '" placeholder="First Name ' + inputCount + '"><br><br>').appendTo(input);
lname = $('<input type="text" name="lname' + inputCount + '" placeholder="Last Name ' + inputCount + '"><br><br>').appendTo(input);
dob = $('<input type="text" name="dob' + inputCount + '" placeholder="Date Of Birth ' + inputCount + '"><br><br>').appendTo(input);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<form action="results.php" method="post">
<body>
<span id="box"></span>
<button type="button" onclick="newUser()">Add User</button>
<br>
<br>
<input type="submit" value="Submit">
</body>
</form>
最佳答案
您的请求已发送至 PHP。在 $_REQUEST
中搜索请求参数错误。您需要在 $_POST
中搜索它们.
您需要定义一个name
属性到要传递的表单字段。在你的newUser
javascript 函数将新用户的数据添加到 html 表单中。使用 jQuery,您可以执行类似 $("#box").append(<your code>)
的操作.
您的代码应该类似于 input
,其中有 name
以及所需的值。然后,在 results.php 中解析具有给定名称的值并插入必要的值。
关于javascript - 如何使用 Php 中的 Foreach 或任何其他方式来实现此目标,将 jquery textBox 中的数据插入到 MySql 数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30963791/