Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Form to Submit into CSV file
    primarykey
    data
    text
    <p>I would like to submit a form and get the info written into the CSV file and stored in the hosting. And every new form should add a new line in csv. Also, lets say I have few groups that a user can join - A,b,c,d,e. How do I make it so if user choose to join 2 or three groups(1,2 and 3rd groups), it is going to store this info as 123 in the same cell. Following is my HTML code:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Reg&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" name="form1" method="post" action="post.php"&gt; &lt;table width="597" class="formatTblClass"&gt; &lt;tr&gt; &lt;th colspan="4"&gt;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="99"&gt;&lt;span&gt;First Name&lt;/span&gt;&lt;/td&gt; &lt;td width="217"&gt;&lt;input class="" type="text" name="fn" id="fn" /&gt;&lt;/td&gt; &lt;td width="99"&gt;&lt;span&gt;Last Name&lt;/span&gt;&lt;/td&gt; &lt;td width="211"&gt;&lt;input class="" name="ln" type="text" id="ln" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Phone&lt;/td&gt; &lt;td&gt;&lt;input class="" type="text" name="phone" id="phone" /&gt;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="4"&gt;Check groups that you would like to receive updates about&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input name="1" type="checkbox" id="1" value="a" /&gt;&lt;/td&gt; &lt;td&gt;A&lt;/td&gt; &lt;td&gt;&lt;input name="4" type="checkbox" id="4" value="b" /&gt;&lt;/td&gt; &lt;td&gt;B&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input name="2" type="checkbox" id="2" value="c" /&gt;&lt;/td&gt; &lt;td&gt;C&lt;/td&gt; &lt;td&gt;&lt;input name="5" type="checkbox" id="5" value="d" /&gt;&lt;/td&gt; &lt;td&gt;D&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input name="3" type="checkbox" id="3" value="e" /&gt;&lt;/td&gt; &lt;td&gt;E&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;td&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="4"&gt; &lt;div align="center"&gt; &lt;input type="submit" name="Submit" id="Submit" value="Submit" /&gt; &lt;input type="reset" name="Reset" id="button" value="Reset" /&gt; &lt;/div&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and this is my post.php file:</p> <pre><code>&lt;?php $fn = $_POST['fn']; $ln = $_POST['ln']; $phone = $_POST['phone']; $1 = (isset($_POST['1'])) ? $_POST['1'] : 'No'; $2 = (isset($_POST['2'])) ? $_POST['2'] : 'No'; $3 = (isset($_POST['3'])) ? $_POST['3'] : 'No'; $4 = (isset($_POST['4'])) ? $_POST['4'] : 'No'; $5 = (isset($_POST['5'])) ? $_POST['5'] : 'No'; //validate if(empty($fn) || empty($ln) || empty($phone)){//show the form $message = 'Fill in areas in red!'; $aClass = 'errorClass'; //this is where the creating of the csv takes place $cvsData = $phone . "," . $fn . "," . $ln . "," . $phone . "," . $1 ."\n"; $fp = fopen("formTest.csv","a"); // $fp is now the file pointer to file $filename if($fp){ fwrite($fp,$cvsData); // Write information to the file fclose($fp); // Close the file ?&gt; </code></pre> <p>When I submit the form, I get a blank page. What is wrong? index.html, post.php and testForm.csv are all in the same folder.</p>
    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.
    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