0 レビュー
1 回答
html-PHP、テキストファイルおよび配列
PHPに書き込みたい次のHTMLコードがあります。 (この例の最後に、これまでに持っていたものがあります。)
<form action="action.php" method="post" />
Please indicate if you us Mathworks MATLAB: <br>
<input type="radio" name="question" value="yes" checked> Yes<br>
<input type="radio" name="question" value="no"> No<br>
If yes, please indicate which of these currently purchased toolboxes you use $
form action="action.php" method="post" />
Please indicate if you us Mathworks MATLAB: <br>
<input type="radio" name="rad" value="yes" checked> Yes<br>
<input type="radio" name="rad" value="no"> No<br>
If yes, please indicate which of these currently purchased toolboxes you use $
<input type="checkbox" name="tool" value="Control">Control Systems Toolbox<br>
<input type="checkbox" name="tool" value="Image">Image Processing Toolbox<br>
<input type="checkbox" name="tool" value="Optimiz">Optimization Toolbox<br>
<input type="checkbox" name="tool" value="Robust">Robust Control Toolbox<br>
<input type="checkbox" name="tool" value="Signal">Signal Processing Toolbox<br>
Please enter a comma separated list of toolboxes you would like to use for you$
<input type="text" name="textquestion" value=""><br>
<input type="submit" value="Submit">
ユーザーが複数のチェックボックスをオンにできるようにチェックボックスを配列に配置する方法を探しています。その回答は、他の回答と一緒にテキストファイルにも保存されます。
<?php
$file = "data.txt";
if(insset($_POST['tool'])){
$tool= $_POST['tool'];
foreach($tool as $tol=>$value){
}
}
if (isset($_POST['rad']) && value && ($_POST['question'])) {
$fh = fopen($file, 'w+');
$text = $_POST['rad']. ' ' .$value. ' ' .$_POST['question'];
fwrite($fh,$text); // Write form data to the file
fclose($fh); // Close the file
}
?>
わからない
0
レビュー
答え :
解決策:
まず、HTMLコードは適切ではありません。次のようにする必要があります:
<form action="action.php" method="post" />
Please indicate if you us Mathworks MATLAB: <br>
<input type="radio" name="question" value="yes" checked> Yes<br>
<input type="radio" name="question" value="no"> No<br>
If yes, please indicate which of these currently purchased toolboxes you use $
Please indicate if you us Mathworks MATLAB: <br>
<input type="radio" name="rad" value="yes" checked> Yes<br>
<input type="radio" name="rad" value="no"> No<br>
If yes, please indicate which of these currently purchased toolboxes you use $
<input type="checkbox" name="tool[]" value="Control">Control Systems Toolbox<br>
<input type="checkbox" name="tool[]" value="Image">Image Processing Toolbox<br>
<input type="checkbox" name="tool[]" value="Optimiz">Optimization Toolbox<br>
<input type="checkbox" name="tool[]" value="Robust">Robust Control Toolbox<br>
<input type="checkbox" name="tool[]" value="Signal">Signal Processing Toolbox<br>
Please enter a comma separated list of toolboxes you would like to use for you$
<input type="text" name="textquestion" value=""><br>
<input type="submit" value="Submit">
したがって、チェックボックスはすべて考慮されます。
次に、新しい配列を作成するには、次を使用します: $xxx = array();
。
したがって、phpファイルに次のように記述します:
<?php
$file = "data.txt";
if (!empty($_POST['tool'])) {
$text = implode(',', $_POST['tool']);
}
if (condition) {
$fh = fopen($file, 'w+');
fwrite($fh,$text); // Write form data to the file
fclose($fh); // Close the file
}
?>
適切と思われるように変更した後。
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。