gpt4 book ai didi

PHP - 无法从 HTML 表单提交访问 POST 值

转载 作者:行者123 更新时间:2023-12-01 00:17:26 24 4
gpt4 key购买 nike

<分区>

我在尝试提交表格时收到此错误(4 次):

Notice: Undefined index: accountid in php/ChartOfAccountsInclude.php on >line 106

这是我代码中的第 106 行

$account_id = $_POST["accountid"][$i];

我正在尝试从本地数据库加载表数据。然后我允许用户访问某些字段以更改值。完成后,他们按下按钮提交,这就是我收到上述错误的时间。数据库中目前有四个帐户,这意味着每次我的代码循环遍历 POST 值时,它都无法检索 accountid。我已经在下面粘贴了相关代码:

用户页面 ChartOfAccounts.php

<?php
include("view/SiteHeader.php");
include('php/ChartOfAccountsInclude.php');
?>

<html>
<head>
<title>Chart of Accounts</title>
</head>

<body>
<br/>
<h2>Chart of Accounts</h2>
<form action="" method="post">
<div>
<?php retrieveChart() ;?>
</div>

<div class="container">
<button type="submit" name="submitMods" class="btn btn-outline-secondary">Submit Account Modifications</button>
</div>
</form>
<?php if($submit_err) : ?>
<?php generateError('warning', 'Account could not be updated.') ?>
<?php endif; ?>
</body>
</html>

PHP 包含 ChartOfAccountsInclude.php

<?php
include_once('php/session.php');
$sql = "SELECT * FROM Accounts";
$result = mysqli_query($db,$sql);
$count = mysqli_num_rows($result);
$submit_err = FALSE;
$submitaccount_err = FALSE;

function retrieveChart() {
global $db;
$funcSQL = "SELECT * FROM Accounts";
$funcResult = mysqli_query($db,$funcSQL);

echo '<table border="1" class="table table-bordered table-hover">
<thead>
<tr>
<th>Account ID</th>
<th>Account Name</th>
<th>Date Created</th>
<th>Type</th>
<th>Term</th>
<th>Status</th>
<th>Created By</th>
</tr>
</thead>';

while($row = mysqli_fetch_array($funcResult))
{
$current = $longterm = $active = $inactive = $debi = $credit = $asset = $expense = $liability = $equity = $revenue = "";
$curusr = $row['user_id'];
$getUsernameSQL = "SELECT username FROM User_accounts WHERE user_id = $curusr";
$usernameResult = mysqli_query($db,$getUsernameSQL);
$usernameRow = mysqli_fetch_array($usernameResult);

switch ($row['term']) {
case 'Current':
$current = "selected = \"selected\"";
break;
case 'Long Term':
$longterm = "selected = \"selected\"";
break;
}
switch ($row['account_status']) {
case 'Active':
$active = "selected = \"selected\"";
break;
case 'Inactive':
$inactive = "selected = \"selected\"";
break;
}
switch ($row['type']) {
case 'Asset':
$asset = "selected = \"selected\"";
break;
case 'Expense':
$expense = "selected = \"selected\"";
break;
case 'Liability':
$liability = "selected = \"selected\"";
break;
case 'Equity':
$equity = "selected = \"selected\"";
break;
case 'Revenue':
$revenue = "selected = \"selected\"";
break;
}

echo '<tr>';
echo '<td> <input name="accountid[]" disabled value="' . $row['account_id'] . '"> </td>';
echo '<td> <input name="accountname[]" value="' . $row['account_name'] . '"> </td>';
echo '<td> <input name="datecreated[]" disabled value="' . $row['date_created'] . '"> </td>';
echo '<td>
<select name="type[]">
<option '.$asset.'>Asset</option>
<option '.$expense.'>Expense</option>
<option '.$liability.'>Liability</option>
<option '.$equity.'>Equity</option>
<option '.$revenue.'>Revenue</option>
</select>
</td>';
echo '<td>
<select name="term[]">
<option '.$current.'>Current</option>
<option '.$longterm.'>Long Term</option>
</select>
</td>';
echo '<td>
<select name="accountstatus[]" value="' . $row['account_status'] . '">
<option '.$active.'>Active</option>
<option '.$inactive.'>Inactive</option>
</select>
</td>';
echo '<td>
<input name="user_id[]" disabled value="' . $usernameRow['username'] . '">
</td>';
echo '</tr>';
}
echo '</table>';
}

if( isset($_POST['submitMods']) ) {
$i = 0;

while($i < $count) {
$account_id = $_POST["accountid"][$i];
$account_name = mysqli_real_escape_string($db,$_POST['accountname'][$i]);
$type = mysqli_real_escape_string($db,$_POST['type'][$i]);
$term = mysqli_real_escape_string($db,$_POST['term'][$i]);
$account_status = mysqli_real_escape_string($db,$_POST['accountstatus'][$i]);

$updateAccountsql = "
UPDATE Accounts
SET
account_id = '$account_id',
account_name = '$account_name',
type = '$type',
term = '$term',
account_status = '$account_status'
WHERE account_id = '$account_id'";

if($account_name == "") {
$submit_err = TRUE;
} else {
$updateResult = mysqli_query($db,$updateAccountsql);
}
$i++;
}

if(!$submit_err) {
//header("Location: ChartOfAccounts.php");
}
}
?>

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com