내가 가진 PHP 할당에 문제가 있습니다. 양식 입력을 생성하기 위해 PHP 스크립트를 만들었고 입력 데이터를 가져 와서 텍스트 문서에 삽입해야합니다. 그래서 두 개의 입력과 텍스트 문서에 데이터를 쓸 함수를 생성하는 코드를 작성했습니다. 그러나 내 텍스트 문서가 비어있게 나타납니다. 텍스트 입력에서 여러 값을 가져 와서 텍스트 문서에 삽입하는 함수를 제대로 정의하는 방법은 무엇입니까? 당신은 코드의 상단에 $item_value
에 값을 할당 할 때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