<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>save php data to csv Archives - Cody Paste</title>
	<atom:link href="https://www.codypaste.com/tag/save-php-data-to-csv/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codypaste.com/tag/save-php-data-to-csv/</link>
	<description>THE WEB PLAYGROUND</description>
	<lastBuildDate>Fri, 10 Feb 2023 04:27:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://www.codypaste.com/wp-content/uploads/2022/12/cropped-codypaste-32x32.png</url>
	<title>save php data to csv Archives - Cody Paste</title>
	<link>https://www.codypaste.com/tag/save-php-data-to-csv/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Save Data to Excel/CSV Instead of MySQL</title>
		<link>https://www.codypaste.com/save-data-to-excel/</link>
					<comments>https://www.codypaste.com/save-data-to-excel/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[Admin]]></dc:creator>
		<pubDate>Thu, 05 Jan 2023 08:03:02 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[csv in php]]></category>
		<category><![CDATA[save data to csv]]></category>
		<category><![CDATA[save php data to csv]]></category>
		<guid isPermaLink="false">https://www.codypaste.com/?p=859</guid>

					<description><![CDATA[<p>If you want to save &#8216;Form&#8217; data or any other data to &#8216;Excel/CSV&#8217;, you are on the right blog. Here we will save Form Data to a &#8216;CSV&#8217; File instead of any Database, we are going to use PHP for this. (We are assuming you have knowledge of PHP) So let&#8217;s get started. &#160; STEP &#8230; </p>
<p class="link-more"><a href="https://www.codypaste.com/save-data-to-excel/" class="more-link">read more<span class="screen-reader-text"> "Save Data to Excel/CSV Instead of MySQL"</span></a></p>
<p>The post <a href="https://www.codypaste.com/save-data-to-excel/">Save Data to Excel/CSV Instead of MySQL</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you want to save &#8216;Form&#8217; data or any other data to &#8216;Excel/CSV&#8217;, you are on the right blog.</p>
<p>Here we will save Form Data to a &#8216;CSV&#8217; File instead of any Database, we are going to use PHP for this.</p>
<p>(We are assuming you have knowledge of PHP)</p>
<p>So let&#8217;s get started.</p>
<p>&nbsp;</p>
<h4>STEP 1:</h4>
<p>Create a CSV File &#8216;<strong>contact_data.csv</strong>&#8216;. (Open Ms Excel and save a file in CSV Format)</p>
<p>Write the column name in the first row of the &#8216;contact_data.csv&#8217;.</p>
<p>(Here we are writing &#8220;sr_no&#8221;,&#8221;name&#8221;,&#8221;email&#8221;,&#8221;subject&#8221;,&#8221;message&#8221; )</p>
<p>&nbsp;</p>
<h4>STEP 2:</h4>
<p>Create a simple HTML Form <strong>index.html</strong> with action &#8216;post.php&#8217;, Code given below</p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;form action="post.php" method="post"&gt;
   &lt;h3 align="center"&gt;Contact Form&lt;/h3&gt;
   &lt;br /&gt;     
   &lt;div class="form-group"&gt;
      &lt;label&gt;Enter Name&lt;/label&gt;
      &lt;input type="text" name="name" placeholder="Enter Name" class="form-control" value="" /&gt;
   &lt;/div&gt;
   &lt;div class="form-group"&gt;
      &lt;label&gt;Enter Email&lt;/label&gt;
      &lt;input type="text" name="email" class="form-control" placeholder="Enter Email" value="" /&gt;
   &lt;/div&gt;
   &lt;div class="form-group"&gt;
      &lt;label&gt;Enter Subject&lt;/label&gt;
      &lt;input type="text" name="subject" class="form-control" placeholder="Enter Subject" value="" /&gt;
   &lt;/div&gt;
   &lt;div class="form-group"&gt;
      &lt;label&gt;Enter Message&lt;/label&gt;
      &lt;textarea name="message" class="form-control" placeholder="Enter Message"&gt;&lt;/textarea&gt;
   &lt;/div&gt;
   &lt;div class="form-group" align="center"&gt;
      &lt;input type="submit" name="submit" class="btn btn-info" value="Submit" /&gt;
   &lt;/div&gt;
&lt;/form&gt;</pre><p>&nbsp;</p>
<h4>STEP 3:</h4>
<p>Create <strong>Action</strong> File &#8216;<strong>post.php</strong>&#8216;, Code given below.</p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;?php
$error = "";
$name = "";
$email = "";
$subject = "";
$message = "";

function clean_text($string)
{
    $string = trim($string);
    $string = stripslashes($string);
    $string = htmlspecialchars($string);
    return $string;
}

if (isset($_POST["submit"])) {
    if (empty($_POST["name"])) {
        $error .=
            '&lt;p&gt;&lt;label class="text-danger"&gt;Please Enter your Name&lt;/label&gt;&lt;/p&gt;';
    } else {
        $name = clean_text($_POST["name"]);
        if (!preg_match("/^[a-zA-Z ]*$/", $name)) {
            $error .=
                '&lt;p&gt;&lt;label class="text-danger"&gt;Only letters and white space allowed&lt;/label&gt;&lt;/p&gt;';
        }
    }
    if (empty($_POST["email"])) {
        $error .=
            '&lt;p&gt;&lt;label class="text-danger"&gt;Please Enter your Email&lt;/label&gt;&lt;/p&gt;';
    } else {
        $email = clean_text($_POST["email"]);
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $error .=
                '&lt;p&gt;&lt;label class="text-danger"&gt;Invalid email format&lt;/label&gt;&lt;/p&gt;';
        }
    }
    if (empty($_POST["subject"])) {
        $error .=
            '&lt;p&gt;&lt;label class="text-danger"&gt;Subject is required&lt;/label&gt;&lt;/p&gt;';
    } else {
        $subject = clean_text($_POST["subject"]);
    }
    if (empty($_POST["message"])) {
        $error .=
            '&lt;p&gt;&lt;label class="text-danger"&gt;Message is required&lt;/label&gt;&lt;/p&gt;';
    } else {
        $message = clean_text($_POST["message"]);
    }

    if ($error == "") {
        $file_open = fopen("contact_data.csv", "a");
        $no_rows = count(file("contact_data.csv"));
        if ($no_rows &gt; 1) {
            $no_rows = $no_rows - 1 + 1;
        }
        $form_data = [
            "sr_no" =&gt; $no_rows,
            "name" =&gt; $name,
            "email" =&gt; $email,
            "subject" =&gt; $subject,
            "message" =&gt; $message,
        ];
        fputcsv($file_open, $form_data);
        $error =
            '&lt;label class="text-success"&gt;Thank you for contacting us&lt;/label&gt;';
        $name = "";
        $email = "";
        $subject = "";
        $message = "";
    }
}

echo $error;
?&gt;</pre><p>&nbsp;</p>
<p><span style="color: #008000;"><a style="color: #008000;" href="https://github.com/vipulrai/Save-to-Excel-CSV" target="_blank" rel="noopener"><strong>DOWNLOAD CODE</strong></a></span></p>
<p>The post <a href="https://www.codypaste.com/save-data-to-excel/">Save Data to Excel/CSV Instead of MySQL</a> appeared first on <a href="https://www.codypaste.com">Cody Paste</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codypaste.com/save-data-to-excel/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
