Note that there are some explanatory texts on larger screens.

plurals
  1. PORead .CSV file in PHP as a table
    primarykey
    data
    text
    <p>I am currently on a project where I need some information to be posted to a csv file and then read back so the previous information can be seen and then edited by the user. Kind of like a database table where the information will be in the cell it should be with some text next to that in another row.</p> <p>At the minute my code has two tables, one showing the information from the csv and one which sends the data to the csv, but I want this to be merged so that they can see what the previously created information was and then they can edit this information click submit and that is the information which will the appear in the table.</p> <p>Here is my code at the minute...</p> <pre><code>$myfile = "outputfile.csv"; if (!isset($_POST['submit'])) { $f = fopen($myfile, 'r'); echo "&lt;table&gt;"; while (($line = fgetcsv($f)) !== false) { echo "&lt;tr&gt;"; foreach ($line as $cell) { echo "&lt;td&gt;" . htmlspecialchars($cell) . "&lt;/td&gt;"; } echo "&lt;/tr&gt;\n"; } fclose($f); echo "\n&lt;/table&gt;"; echo " &lt;form action='' method='POST'&gt; &lt;table border='1'&gt; &lt;tr&gt; &lt;td&gt;&lt;input name='var1' type='text'&gt;&lt;/td&gt; &lt;td&gt;MMR&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input name='var2' type='text'&gt;&lt;/td&gt; &lt;td&gt;FIVE_IN_ONE&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input name='var3' type='text'&gt;&lt;/td&gt; &lt;td&gt;BOOSTER&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input name='var4' type='text'&gt;&lt;/td&gt; &lt;td&gt;MENC&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;input name='submit' type='submit' value='Submit'&gt; &lt;/form&gt;"; } else { $text1 = $_POST['var1']; $text2 = $_POST['var2']; $text3 = $_POST['var3']; $text4 = $_POST['var4']; $fh = fopen($myfile, 'w+'); fwrite($fh, $text1 . "\r\n" . $text2 . "\r\n" . $text3 . "\r\n" . $text4); fclose($fh); echo $text1 . "&lt;br&gt;" . $text2 . "&lt;br&gt;" . $text3 . "&lt;br&gt;" . $text4; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload