lundi 18 juin 2018

PHP, Text files and Arrays

I have the following HTML code that I would like to write into PHP. (At the end of this example I have what I have so far.)

<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">

I am looking for a way to put the checkboxes into an array so that the user can check more then one box and that answer is also stored in the text file along with the other answer.

<?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
}
?>




Aucun commentaire:

Enregistrer un commentaire