I'm trying to display a CSV file in a browser and print the selected (via radio button) row.
Here's my code to print the CSV file (with a radio button next to each row):
<?php
echo "<html><body><table border='1'>";
$f = fopen("data.csv", "r");
$row = 1;
echo "<form method='post' action='submit.php'>";
while (($line = fgetcsv($f)) !== false) {
$to_print = implode(",", $line); // added this and changed value below (to use it)
echo "<tr><td><input type='radio' name='env[$row]' value='$to_print' /></td>";
foreach ($line as $cell) {
echo "<td contenteditable='true'>" . htmlspecialchars($cell) . "</td>";
}
echo "</tr>\n";
++$row;
}
fclose($f);
echo "</table><br><Input type='submit'></form></span></body></html>";
?>
I have a submit button at the bottom that (when clicked) should pass the data in the selected row to submit.php which should print it.
Here's the submit.php:
<?php
echo "<html><body>";
print_r($_POST); // this prints what I need
if (! empty($_POST['env'])) {
$j=0;
foreach ($_POST['env'] as $env) {
// Can't get anything to print in here
++$j;
}
}
echo "</body></html>";
?>
But it prints nothing. I'm guessing it has something to do with the 'value' of my radio button:
value='<?php echo $line;?>]'
That can't be right...
Any suggestions would be great. Thanks!
$lineis an array. If you want to echo it as a wholeimplode()it first. And you will get the column names first.env