私はPHPの割り当てに問題があります。私はフォーム入力を生成するPHPスクリプトを作成しました。私は入力からデータを取り出し、それをテキスト文書に挿入する必要があります。そこで、2つの入力を生成するコードと、テキスト文書にデータを書き込む関数を作成しました。しかし、私のテキスト文書は空白に見えます。テキスト入力から複数の値を取り込んでテキスト文書に挿入する関数を正しく定義するにはどうすればよいですか?ここに私のコードは、これまでのところです:PHPで生成された入力からテキストファイルに挿入
<form method='post'>
<table border='0' cellpadding='3' cellspacing='5'>
<tr>
<td><h2>Item</h2></td>
<td><h2>Amount</h2></td>
</tr>
<?php
for($row=1; $row<5;$row++)
{
$item_name='item_name'.$row;
$item_value = $_POST[$item_name];
$amount_name='amount_name'.$row;
$amount_value = $_POST[$amount_name];
echo
"<tr>
<td><input type='text' name='$item_name' value='$item_value' /></td>
<td><input type='text' name='$amount_name' value='$amount_value' /></td>
";
if (!empty($amount_value))
{
if(is_numeric($amount_value))
{
$total = $total + $amount_value;
}
else {
echo
"<td class='bad'>Amount Invalid: $amount_value</td>";
$error_count++;
}
}
echo"
</tr>
";
}
?>
<tr>
<td colspan='2'>
<input name='' type='submit' value='Submit' />
</td>
</table>
<?php
if ($error_count > 0)
{
echo "<br /><span class='bad' />Errors: $error_count</span>";
}
else
{
echo "<br />Total: $total";
}
if ($error_count == 0)
{
addData();
}
//Function
function addData()
{
$myFile = "bills.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $amount_value;
fwrite($fh, $stringData);
$stringData = $item_value;
fwrite($fh, $stringData);
fclose($fh);
}
?>
</form>
スクリプトの上部に 'error_reporting(E_ALL);'を追加します。次に、関数のパラメータを追加することを検討します。 – mario