我有一个文件,我有两个查询。一个从表中选择数据并对其进行混洗,然后第二个查询将混洗结果插入到我的另一个名为user_players的数据库中。
在我改变第一个查询之前,这一切都很完美。我将它移动到另一个文件并使用AJAX调用进行结构化。现在我的第二个查询是破坏,它不会发送到我的数据库。我收到未定义索引和缺少变量的错误,但我包含了所有变量。这可能有什么问题?如果有人需要查看第一个查询,因为这是我收到信息的地方,请告诉我。
这是失败的,我收到以下错误:
注意:未定义的索引:id in 第235行/home4/dhgh/public_html/example.com/userCreator.php
警告:为foreach()提供的参数无效 第235行/home4/gddgg/public_html/example.com/userCreator.php
LINE 235:
foreach ($_POST['id'] as $i => $shuffle_id) {
我的第二个查询的代码。
<form method="post">
<input type="submit" value="Finalize Draft Order" name="insert">
</form>
<?php
foreach ($array as $result) {
$shuffle_firstname = htmlentities($result['firstname']);
$shuffle_lastname = htmlentities($result['lastname']);
$shuffle_id = htmlentities($result['id']);
$shuffle_username = htmlentities($result['username']);
$shuffle_email = htmlentities($result['email']);
?>
<input type="hidden" name="firstname[]" value="<?php echo $shuffle_firstname; ?>">
<input type="hidden" name="lastname[]" value="<?php //echo $shuffle_lastname; ?>">
<input type="hidden" name="id[]" value="<?php echo $shuffle_id; ?>">
<input type="hidden" name="username[]" value="<?php echo $shuffle_username; ?>">
<input type="hidden" name="email[]" value="<?php echo $shuffle_email; ?>">
<?php
}
if (isset($_POST['insert'])) {
$con = mysqli_connect("localhost", "", "", "");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt2 = $con->prepare("INSERT INTO user_players (user_id, firstname, lastname, username, email) VALUES (?, ?, ?, ?, ?)");
if ( false===$stmt2 ) {
// Check Errors for prepare
die('Add to user players prepare() failed: ' . htmlspecialchars($con->error));
}
$stmt2->bind_param('issss', $shuffle_id, $shuffle_firstname, $shuffle_lastname, $shuffle_username, $shuffle_email);
foreach ($_POST['id'] as $i => $shuffle_id) {
$shuffle_firstname = $_POST['firstname'][$i];
$shuffle_lastname = $_POST['lastname'][$i];
$shuffle_username = $_POST['username'][$i];
$shuffle_email = $_POST['email'][$i];
$stmt2->execute() or
die('Add to user players execute() failed: ' . htmlspecialchars($stmt2->error));
}