<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ crm - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ crm - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 23 Jun 2026 22:45:50 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/crm/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Build yourself a simple CRM from scratch in PHP and MySQL ]]>
                </title>
                <description>
                    <![CDATA[ By Richard Customer Relationship Management (CRM) is a system that manages customer interactions and data throughout the customer life-cycle between the customer and the company across different channels. In this tutorial, we are going to build a cus... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/building-a-simple-crm-from-scratch-in-php-58fef061b075/</link>
                <guid isPermaLink="false">66c346a5160da468ed76f172</guid>
                
                    <category>
                        <![CDATA[ crm ]]>
                    </category>
                
                    <category>
                        <![CDATA[ PHP ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 01 Mar 2017 05:26:50 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*9ZxDtBiAUyVo6anPUJxkcg.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Richard</p>
<p>Customer Relationship Management (CRM) is a system that manages customer interactions and data throughout the customer life-cycle between the customer and the company across different channels. In this tutorial, we are going to build a custom CRM in PHP, which a sales team can use to track customers through the entire sales cycle.</p>
<p>We’ll be creating a simple CRM system for salespeople to:</p>
<ul>
<li>Access their tasks</li>
<li>View their leads</li>
<li>Create new tasks for each lead</li>
<li>Create new opportunity</li>
<li>Close a sale</li>
</ul>
<p>Sales managers will be able to:</p>
<ul>
<li>Manage all customers</li>
<li>Manage sales team</li>
<li>View current sales activities</li>
</ul>
<p><a target="_blank" href="https://github.com/phpcontrols/phpgrid-custom-crm">Download Demo Files</a></p>
<h3 id="heading-building-blocks-of-a-crm">Building Blocks of a CRM</h3>
<p>Here is a list of the essential components of the CRM:</p>
<ul>
<li><strong>Leads</strong>: initial contacts</li>
<li><strong>Accounts</strong>: Information about the companies you do business with</li>
<li><strong>Contact</strong>: Information about the people you know and work with. Usually, one account has many contacts</li>
<li><strong>Opportunities</strong>: Qualified leads</li>
<li><strong>Activities</strong>: Tasks, meetings, phone calls, emails and any other activities that allow you to interact with customers</li>
<li><strong>Sales</strong>: Your sales team</li>
<li><strong>Dashboard</strong>: CRM dashboards are much more than just eye candy. They should deliver key information at a glance and provide links to drill down for more details.</li>
<li><strong>Login</strong>: Salespeople and managers have different roles in the system. Managers have access to reports and sales pipeline information.</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*19oQRWbZyumceXfU." alt="Image" width="683" height="240" loading="lazy"></p>
<h3 id="heading-system-requirements">System Requirements</h3>
<ul>
<li>PHP 5.3+,</li>
<li>MySQL or MariaDB</li>
<li><a target="_blank" href="http://phpgrid.com/">phpGrid</a></li>
</ul>
<h3 id="heading-create-crm-database">Create CRM Database</h3>
<p>We will start by creating our custom CRM database. The main tables we will be using are:</p>
<ul>
<li><strong>contact</strong> — contains basic customer data</li>
<li><strong>notes</strong> — holds information collection from Contact by sales people.</li>
<li><strong>users</strong> — information about sales people</li>
</ul>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*gJgr4DrRJ3O_OEYr." alt="Image" width="524" height="423" loading="lazy"></p>
<p>The <strong>Contact</strong> table contains basic customer information including names, company addresses, project information, and so forth.</p>
<p>The <strong>Notes</strong> table stores all sales activity information such as meetings and phone calls.</p>
<p>The <strong>Users</strong> table holds login information about users of the system such as usernames and passwords. Users can also have roles, such as Sales or Manager.</p>
<p>All other tables are <a target="_blank" href="https://www.quora.com/In-database-what-are-lookup-tables">lookup tables</a> to join to the three main relational database tables.</p>
<ul>
<li><strong>contact_status</strong> — contains contact status such as Lead and Opportunity. Each indicates a different stage in a typical sales cycle</li>
<li><strong>task_status</strong> — the task status can be either Pending or Completed</li>
<li><strong>user_status</strong> — a sale person can be Active or Inactive</li>
<li><strong>todo_type</strong> — a type of task either Task or Meeting</li>
<li><strong>todo_desc</strong> — description of a task such as Follow Up Email, Phone Call, and Conference etc.</li>
<li><strong>roles</strong> — a user can be either a Sales Rep or a Manager</li>
</ul>
<h4 id="heading-complete-database-schema-diagram">Complete Database Schema Diagram</h4>
<p>A database schema is the structure that represents the logical view such as tables, views, or primary and foreign keys of the entire database. A database schema includes entities and the relationship among them.</p>
<p>It is a good practice to have one primary key for each table in a relational database. A primary key is a unique identifier for each record. It can be the social security number (SSN), vehicle identification number (VIN), or auto-increment number. This is a unique number that is generated when a new record is inserted into a table.</p>
<p>Below is the database diagram of our simple CRM. The key symbol in each table represents the table primary key. The magnifying glass indicates foreign key linking another table in the database. Sometimes we call it the “lookup” table.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*qExvrxjr5WZERLEO." alt="Image" width="800" height="507" loading="lazy"></p>
<h4 id="heading-installsql">install.sql</h4>
<p>Once you have an understanding of the database table structure, find the “install.sql” script in the <code>db</code> folder and use a MySQL tool such as <a target="_blank" href="http://www.mysql.com/products/workbench/">MySQL Workbench</a> or <a target="_blank" href="https://www.sequelpro.com/">Sequel Pro</a> to run the SQL script. It should create a new relational database named <code>custom_crm</code> and its database tables.</p>
<h3 id="heading-a-side-note-on-zenbase">A Side Note on ZenBase</h3>
<pre><code>The CRM application is also one <span class="hljs-keyword">of</span> the many application templates readily available at ZenBase (built on the top <span class="hljs-keyword">of</span> phpGrid) <span class="hljs-keyword">for</span> anyone — <span class="hljs-keyword">with</span> or without coding skills — to use and customize <span class="hljs-keyword">for</span> their own needs.
</code></pre><h3 id="heading-setup-phpgrid">Setup phpGrid</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*FZ9ZZsPaUVIiGZkgcbpSDQ.jpeg" alt="Image" width="800" height="450" loading="lazy"></p>
<p>Our CRM contains many datagrids. The datagrid is a spreadsheet-like data table that displays rows and columns representing records and fields from the database table. The datagrid gives the end-user ability to read and write to database tables on a webpage. We can use a datagrid tool from <a target="_blank" href="http://phpgrid.com/">phpGrid</a>. We use a tool instead of building them from scratch because developing the datagrid is usually tedious and error-prone. The datagrid library will handle all internal database <strong>CRUD (Create, Remove, Update, and Delete)</strong> operations for us with better and faster results with little code. To install phpGrid, follow these steps:</p>
<ol>
<li>Unzip the phpGrid download file.</li>
<li>Upload the phpGrid folder to the <code>phpGrid</code> folder.</li>
<li>Complete the installation by configuring the <code>conf.php</code> file.</li>
</ol>
<p>Before we begin coding, we must specify the database information in <code>conf.php</code>, the phpGrid configuration file. Here is an example of database connection settings:</p>
<ul>
<li><strong>PHPGRID_DB_HOSTNAME</strong> — web server IP or host name</li>
<li><strong>PHPGRID_DB_USERNAME</strong> — database user name</li>
<li><strong>PHPGRID_DB_PASSWORD</strong> — database password</li>
<li><strong>PHPGRID_DB_NAME</strong> — database name of our CRM</li>
<li><strong>PHPGRID_DB_TYPE</strong> — type of database</li>
<li><strong>PHPGRID_DB_CHARSET</strong> — always ‘utf8’ in MySQL</li>
</ul>
<p>To learn more about configuring phpGrid, check out <a target="_blank" href="http://phpgrid.com/documentation/installation/">phpGrid complete installation guide</a>.</p>
<h3 id="heading-page-template">Page Template</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*nnv7_XJ9KD0zLXqK." alt="Image" width="800" height="539" loading="lazy"></p>
<p>Before we can start building our first page of the CRM, it is a good practice to make the reusable page items such as header and footer.</p>
<p>The page will comprise of a header, menu, body and footer. We will start by creating a reusable page template.</p>
<h3 id="heading-headphp">head.php</h3>
<p>This is a basic HTML5 template header. It includes a link to a custom stylesheet that will be created in a later step.</p>
<h3 id="heading-menuphp">menu.php</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*TDduZwwNWj64wN77." alt="Image" width="800" height="68" loading="lazy"></p>
<p>Notice the usage of <code>$_GET['currentPage']</code>. Each page will set a value which will highlight the name of the current page on the top menu bar.</p>
<p>Include the following code in style.css for menu styling (minified). It will transform the above, unordered list into a menu.</p>
<h3 id="heading-footerphp">footer.php</h3>
<p>Simple closing body and html tags.</p>
<h3 id="heading-complete-page-template">Complete Page Template</h3>
<p>This is the complete page template. The main content will go after <code>Section Title</code>.</p>
<h3 id="heading-crm-main-pages">CRM Main Pages</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*z5iaw9R1XH1qCwIeE7-QfA.jpeg" alt="Image" width="800" height="533" loading="lazy"></p>
<p>Are you still with me? Good! We can now finally develop the first page in our CRM.</p>
<p>Our CRM for the sales team members has four pages:</p>
<ul>
<li><strong>Tasks</strong></li>
<li><strong>Leads</strong></li>
<li><strong>Opportunities</strong></li>
<li><strong>Customers/Won</strong></li>
</ul>
<p>Each page indicates a different stage in a typical sales cycle.</p>
<h3 id="heading-sale-people-page-design-mockup">Sale People Page Design Mockup</h3>
<p>Here’s our CRM design mockup for the sales people.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*AS942OO-igxo4ylg8f7m5g.png" alt="Image" width="800" height="512" loading="lazy"></p>
<h3 id="heading-tasks-page">Tasks Page</h3>
<p>When a sales team member logged in, the first page he sees is a list of current tasks.</p>
<p>As you may recall, our Notes table holds all the sales activity information. We can create a datagrid and populate it from the Notes table using phpGrid.</p>
<p>The Tasks page main content is a datagrid. The following two lines will give us a list of tasks of the current sales person.</p>
<ul>
<li>The first line creates a phpGrid object by passing the SELECT SQL statement, its primary key — <code>ID</code>, and then the name of the database table - <code>notes</code>.</li>
<li>The second and the final line calls <a target="_blank" href="http://phpgrid.com/documentation/display/">display()</a> function to render the datagrid on the screen. Check out the <a target="_blank" href="http://phpgrid.com/example/example-1-a-basic-php-datagrid-2/">basic datagrid demo</a> for more detail.</li>
</ul>
<h3 id="heading-leads-page">Leads Page</h3>
<p>The leads page contains list of current leads that the sales person is responsible for. Each Lead can have one or many Notes. We will use the <a target="_blank" href="http://phpgrid.com/example/master-detail-grid/">phpGrid master-detail</a> feature for that.</p>
<p>We also need to use <a target="_blank" href="http://phpgrid.com/documentation/set_query_filterwhere/">set_query_filter</a>() to display only the leads, <code>Status = 1</code>, and only for the current sales person.</p>
<h4 id="heading-contact-status-table">Contact status table</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0*GJDLBk0XN5r9M5NY." alt="Image" width="286" height="186" loading="lazy"></p>
<h3 id="heading-opportunities-page">Opportunities Page</h3>
<p>A Lead becomes an Opportunity once it is qualified. The Opportunities page is similar to the Leads page. The only difference is the filtered status code in set_query_filter is <code>Status = 2</code>.</p>
<h3 id="heading-customerswon-page">Customers/Won Page</h3>
<p>Customers/Won has the <code>Status = 3</code>. Similar to Leads and Opportunities, Customers/Won can also have Notes.</p>
<p>That’s all there is to it for sales people in our simple CRM.</p>
<h3 id="heading-manager-dashboard">Manager Dashboard</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*AI44nH7B8mnNLTKqulmjGA.jpeg" alt="Image" width="800" height="600" loading="lazy">
_Photo by [Unsplash](http://unsplash.com/photos/rS1GogPLVHk?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="_blank" title=""&gt;Eaters Collective on &lt;a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText" rel="noopener" target="<em>blank" title=")</em></p>
<p>The sales manager will have access to all records in the sales pipeline as well as the ability to manage sales team and customer data.</p>
<p>We will have a single web page with tabbed menu similar to the <a target="_blank" href="http://phpgrid.com/example/tabbed-datagrid/">phpGrid tabbed grid demo</a>.</p>
<h3 id="heading-manager-dashboard-design-mockup">Manager Dashboard Design Mockup</h3>
<h4 id="heading-my-sales-reps">My Sales Reps</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Jn0q3g0FMqW6shEXtENR8w.png" alt="Image" width="800" height="487" loading="lazy"></p>
<h3 id="heading-main-content">Main content</h3>
<p>Each tab represents a table in the CRM database. <code>$_GET['gn']</code> will store the table name. It dynamically generates the datagrid based on table name passed.</p>
<p>It’s very easy to integrate jQueryUI Tabs with phpGrid. Please refer to the phpGrid <a target="_blank" href="http://phpgrid.com/example/tabbed-datagrid/">Tabbed Grid demo</a> for more information.</p>
<h3 id="heading-my-sales-rep-page">My Sales Rep Page</h3>
<p>Since a sales manager needs to quickly find out whom a sale person is working with, we added a detail grid <code>$sdg</code> populated from contact table and link with the master grid.</p>
<p><code>sales_rep</code> is the connecting key in <code>contact</code> table to the <code>id</code> that is the foreign key in <code>users</code> table. Remember the <code>users</code> stores all of our sales people information.</p>
<h3 id="heading-screenshots">Screenshots</h3>
<h4 id="heading-crm-sales-screen">CRM — Sales Screen</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*e_osyaKXAm8Paj6OTVpCsg.png" alt="Image" width="800" height="338" loading="lazy"></p>
<h4 id="heading-crm-manager-screen">CRM — Manager Screen</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*wMcbdN9Im5jAUhv-mfEN_g.png" alt="Image" width="800" height="350" loading="lazy"></p>
<h3 id="heading-live-demo">Live Demo</h3>
<p><a target="_blank" href="http://phpdatagrid.com/apps/phpgrid-custom-crm/sales/tasks.php">CRM Sales Rep Screen</a> | <a target="_blank" href="http://phpdatagrid.com/apps/phpgrid-custom-crm/managers/pipeline.php">CRM Managers screen</a></p>
<h3 id="heading-need-to-write-even-less-code">Need to Write Even Less Code?</h3>
<p>If you are new to programming and are not yet comfortable with coding, you may want to check out <a target="_blank" href="https://getzenbase.com/"><strong>ZenBase</strong></a> that is built on the top of the phpGrid. The CRM is but one of the <a target="_blank" href="https://getzenbase.com/templates/">many application templates</a> readily available at ZenBase for anyone — <em>with or without</em> coding skills — to use and customize for their own needs.</p>
<h3 id="heading-complete-source-code-on-github">Complete Source Code on GitHub</h3>
<p><a target="_blank" href="https://github.com/phpcontrols/phpgrid-custom-crm"><strong>phpcontrols/phpgrid-custom-crm</strong></a><br><a target="_blank" href="https://github.com/phpcontrols/phpgrid-custom-crm">_phpgrid-custom-crm - Custom CRM Demo - Learn to build yourself a custom CRM in PHP and MySQL, which a sales team can…_github.com</a></p>
<h3 id="heading-thanks-for-reading-if-you-enjoyed-this-article-please-hit-that-clap-button-to-help-others-find-it-and-follow-me-on-twitterhttpstwittercommidlifesaas">Thanks for reading. If you enjoyed this article, please hit that clap button ? to help others find it and f<a target="_blank" href="https://twitter.com/midlifesaas">ollow me on Twitter.</a></h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*v-_G34PI1sMmIxI1xstaYQ.png" alt="Image" width="314" height="161" loading="lazy"></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
