<?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" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yogesh Singh on Medium]]></title>
        <description><![CDATA[Stories by Yogesh Singh on Medium]]></description>
        <link>https://medium.com/@yssyogesh94?source=rss-781e0089d42c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-5RGX5PZ2veePKnCVAFVlQ.jpeg</url>
            <title>Stories by Yogesh Singh on Medium</title>
            <link>https://medium.com/@yssyogesh94?source=rss-781e0089d42c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 04:42:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yssyogesh94/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[TCPDF Adding an Extra Page Automatically — The Rendering Loop Bug]]></title>
            <link>https://medium.com/@yssyogesh94/tcpdf-adding-an-extra-page-automatically-the-rendering-loop-bug-794a342326d7?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/794a342326d7</guid>
            <category><![CDATA[pdf]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Tue, 18 Aug 2026 06:48:20 GMT</pubDate>
            <atom:updated>2026-08-21T07:02:50.043Z</atom:updated>
            <content:encoded><![CDATA[<p>A user reported that their certificate was printing two pages instead of one. No error. No warning in the logs. Just a blank second page with some content on it that was supposed to be on page one.</p><p>That’s the worst kind of bug — silent, visual, and impossible to reproduce until you understand exactly what triggered it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E8qlwb_Qr2XiI0_V.png" /></figure><h3>What Was Happening</h3><p>The certificate plugin I was working on generates a PDF in one of two modes. If a shared template is applied, it renders the template’s elements at their stored positions. If no template is applied, it falls back to a built-in preset layout with fixed content.</p><p>The user had loaded a template, then removed it. From the UI side, the template was gone. But in the database, the private template page still had its element records sitting there — they were never cleaned up when the template was removed.</p><p>Here’s what the rendering loop was doing at the time:</p><pre>foreach ($pages as $page) { <br>    $elements = getElements($page-&gt;id); <br>    if ($elements) { <br>        foreach ($elements as $element) { <br>            $element-&gt;render($pdf); <br>        } <br>     } else { <br>        renderPresetContent($pdf, $page); <br>        renderTextOptions($pdf, $page); <br>     } <br>}</pre><p>The condition inside the loop checks whether elements exist for the current page. If they do, it takes the template branch. If not, it falls back to preset.</p><p>The problem: the private template page still had elements in the DB. So <strong>getElements()</strong> returned results, the loop took the template branch, and one of those stale elements had a <strong>posy</strong> value of 250mm — on a page that was only 210mm tall.</p><h3>What TCPDF Does With an Out-of-Bounds Element</h3><p>TCPDF has auto page break enabled by default. When you try to render anything past the page height, it doesn’t throw an error — it silently creates a new page and renders the content there instead.</p><pre>// TCPDF creates a new page automatically when Y exceeds page height <br>$pdf-&gt;SetAutoPageBreak(true, 0); // An element at Y=250 on a 210mm page: <br>$pdf-&gt;SetXY(10, 250); // 40mm past the bottom edge <br>$pdf-&gt;Cell(...); // TCPDF adds a new page right here, no warning</pre><p>So the stale element, sitting 40mm below the page boundary, triggered an automatic page break. The element rendered at the top of the new page. The user got a two-page certificate with a stray piece of content on page two — and had no idea why.</p><h3>Why the Loop Was Wrong</h3><p>The real bug is not the stale DB records — those are a symptom. The real bug is that the rendering mode was being decided <strong>inside the loop, per page</strong>, using data that could be inconsistent.</p><p>The condition <strong>if ($elements)</strong> is checking whether elements exist for that specific page. But that’s not the same as checking whether the user has actually applied a shared template. A page can have elements for reasons that have nothing to do with the current rendering mode — stale records, leftover migrations, manual DB edits.</p><p>I realised the loop shouldn’t be the one figuring this out. It was checking <strong>$elements</strong> per page and using that to decide the mode — but that’s not the same as checking whether the user actually has a template applied. The data inside the loop was unreliable for that decision.</p><h3>The Fix</h3><p>Set a flag before the loop. Everything inside the loop reads that flag — it never re-derives the mode from per-row data.</p><pre>$useElements = false; <br>if (!empty($customcert-&gt;appliedtemplateid)) { <br>    $templatePages = getPagesByTemplate($customcert-&gt;appliedtemplateid); <br><br>    if ($templatePages) { <br>        $pages = $templatePages; <br>        $useElements = true; <br>    } <br>} <br><br>foreach ($pages as $page) { <br>    addPageToPdf($pdf, $page); <br>    renderDesignOptions($pdf, $page, $customcert); <br>    if ($useElements) { <br>        foreach (getElements($page-&gt;id) as $element) { <br>            $element-&gt;render($pdf); <br>        } <br>    } else { <br>        renderPresetContent($pdf, $page, $customcert); <br>        renderTextOptions($pdf, $page, $customcert); <br>    } <br>}</pre><p><strong>$useElements</strong> is set based on whether a shared template is actually applied — not based on what’s in the database for a given page. When no template is applied, <strong>$useElements</strong> is false and the `else` branch runs for every page, every time. The stale private template elements are never queried. The extra page never appears.</p><h3>Protecting Against TCPDF Overflow Anyway</h3><p>Even with the loop fixed I added a safeguard anyway — because stale records can creep in again. The simpler option is to just disable auto page break while rendering elements. An out-of-bounds element gets clipped instead of triggering a new page:</p><pre>$pdf-&gt;SetAutoPageBreak(false); <br>foreach ($elements as $element) { <br>    $element-&gt;render($pdf); <br>} <br>$pdf-&gt;SetAutoPageBreak(true, 0);</pre><p>If you want more visibility into what’s being skipped, validate positions before rendering instead:</p><pre>function isWithinPage(\stdClass $element, \stdClass $page): bool { <br>    return $element-&gt;posy &lt; $page-&gt;height &amp;&amp; $element-&gt;posx &lt; $page-&gt;width; <br>} <br><br>foreach ($elements as $element) { <br>    if (isWithinPage($element, $page)) { <br>        $element-&gt;render($pdf); <br>    } <br>}</pre><p>That way you can log the skipped elements and trace where the bad values came from.</p><h3>The Pattern, Beyond PDF Generation</h3><p>This isn’t a TCPDF-specific problem. Any time you have two fundamentally different rendering modes sharing a loop, the same mistake is possible:</p><pre>$mode = determineMode($config); // once, outside <br>foreach ($items as $item) { <br>    if ($mode === &#39;A&#39;) { <br>        renderModeA($item); <br>    } else { <br>        renderModeB($item); <br>    } <br>}</pre><p>The same thing happens in report generators that switch between summary and detail views based on per-row data, or in export code that decides between CSV and Excel format inside the row loop. The loop is the wrong place for that call every time.</p><h3>What I Check Now</h3><p>If I’m writing a loop with more than one rendering path, I make sure the decision about which path to use is settled before the loop starts — not derived from whatever the loop happens to find in the database row by row.</p><p>That one change fixed it. And the loop got easier to read too — no more guessing which branch runs and why.</p><p><em>Originally published at </em><a href="https://makitweb.com/tcpdf-extra-page-added-automatically-php/"><em>https://makitweb.com</em></a><em> on August 18, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=794a342326d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Moodle Plugin: Add Database Column with upgrade.php]]></title>
            <link>https://medium.com/@yssyogesh94/moodle-plugin-add-database-column-with-upgrade-php-6163a7e5b90c?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6163a7e5b90c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[moodle]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Sun, 09 Aug 2026 11:49:08 GMT</pubDate>
            <atom:updated>2026-08-10T04:51:13.675Z</atom:updated>
            <content:encoded><![CDATA[<p>I added a new column to my plugin’s database table. Tested locally — everything worked. Deployed to the live site — plugin crashed with a “Column not found” error in front of actual users.</p><p>The column was sitting in my local database. It was not on the live server. Of course it wasn’t. I had added it by running ALTER TABLE directly in phpMyAdmin. That only touched my local machine. The live server had no idea a new column was supposed to exist.</p><p>This is the mistake I see most Moodle developers make once. You do it, the live site breaks, you manually run the SQL on the server at odd hours, and then you learn there’s a proper way to do this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VcH9V2E04iqiW2SG.png" /></figure><h3>Why Manual SQL Doesn’t Scale</h3><p>Running queries directly in phpMyAdmin works fine when you’re the only one touching the database. The moment you have a staging server, a live server, or other developers on the project, manual SQL becomes a liability. Someone always forgets to run it somewhere. And if you’re distributing a plugin to other Moodle sites, you obviously can’t SSH into every installation and run <strong>ALTER TABLE</strong> yourself.</p><p>Moodle solves this with an upgrade system that runs automatically. You describe the database change in PHP, bump a version number, and the next time an admin visits /admin/index.php, Moodle detects the version bump and runs your changes. On every server, every time, without anyone touching the database manually.</p><h3>How the Upgrade System Works</h3><p>Every Moodle plugin has a version.php file with a line like this:</p><pre>$plugin-&gt;version = 2024042200;</pre><p>That number is a 10-digit timestamp — year, month, day, and a two-digit sequence. Moodle stores the last-run version in its database. When you visit /admin/index.php, it compares the stored number to the one in version.php. If version.php is higher, Moodle looks in db/upgrade.php for blocks to run.</p><p>The upgrade file is a function that receives $oldversion - the version that was last saved. Each block checks whether $oldversion is lower than a specific number, and if so, runs the database change and saves a new savepoint. That&#39;s the whole mechanism.</p><h3>Adding a Column the Right Way</h3><pre>// Before <br>$plugin-&gt;version = 2024042200; <br><br>// After <br>$plugin-&gt;version = 2024042201;</pre><p>Increment the last two digits by 1. If you run multiple changes on the same day, use 01, 02, 03, and so on. Never reuse a version number — Moodle silently skips blocks it has already run, so reusing one means your change never runs on existing sites.</p><pre>function xmldb_yourplugin_upgrade($oldversion) { <br>    global $DB; <br>    $dbman = $DB-&gt;get_manager(); <br>    if ($oldversion &lt; 2024042201) { <br>        $table = new xmldb_table(&#39;yourplugin&#39;); <br>        $field = new xmldb_field( <br>            &#39;newcolumn&#39;, <br>            XMLDB_TYPE_INTEGER, <br>            &#39;10&#39;, <br>            null, <br>            XMLDB_NOTNULL, <br>            null, <br>            &#39;0&#39;, // default value <br>            &#39;existingcolumn&#39; // add it after this column <br>        ); <br>        if (!$dbman-&gt;field_exists($table, $field)) { <br>          $dbman-&gt;add_field($table, $field); <br>        } <br>        upgrade_mod_savepoint(true, 2024042201, &#39;yourplugin&#39;); <br>    } <br>    return true; <br>}</pre><p>A few things worth noting here.</p><p>The field_exists() check on line 16 is not optional - it&#39;s the thing that stops your upgrade from crashing on servers that already have the column. Maybe a developer on your team added it manually before you wrote this upgrade. Maybe a previous version of the plugin created it under a different migration. Without field_exists(), running add_field() on an existing column throws a database error and the upgrade fails completely. With it, the block runs harmlessly and moves on.</p><p>Using $dbman-&gt;add_field() instead of a raw ALTER TABLE also matters. Moodle runs on both MySQL and PostgreSQL. Raw ALTER TABLE syntax differs between them. The $dbman methods generate the right SQL for whatever database the site is running on.</p><p>The upgrade_mod_savepoint() call at the end is what tells Moodle to record this version as complete. Forget it and Moodle will re-run the block on the next visit to /admin/index.php.</p><h3>Don’t Forget install.xml</h3><p>upgrade.php handles existing installations. Fresh installs - someone installing your plugin for the first time - use db/install.xml instead. Upgrade blocks never run on a clean install.</p><p>So you need to add the new field to install.xml as well:</p><pre>&lt;FIELD NAME=&quot;newcolumn&quot; TYPE=&quot;int&quot; LENGTH=&quot;10&quot; NOTNULL=&quot;true&quot; DEFAULT=&quot;0&quot; SEQUENCE=&quot;false&quot;/&gt;</pre><p>The easiest way to generate this correctly is through Moodle’s built-in XMLDB editor at <strong>Site Administration → Development → XMLDB editor</strong>. It writes the XML for you — you don’t have to get the attribute names and types right by hand.</p><h3>Common Mistakes That Will Bite You</h3><p>Reusing the same version number</p><p>Second block never runs on sites that already ran the first</p><p>Missing upgrade_mod_savepoint()</p><p>Block re-runs on every admin page visit</p><p>Using ALTER TABLE instead of $dbman</p><p>Breaks on PostgreSQL</p><p>Updating version.php without visiting /admin/index.php</p><p>Upgrade never triggers</p><p>Not adding the field to install.xml</p><p>Fresh installs don’t have the column</p><h3>Running the Upgrade</h3><p>Once you have version.php bumped and upgrade.php written, deploy the files to the server and visit /admin/index.php. Moodle will detect the version difference and show an upgrade confirmation screen. Confirm it and the block runs. You can verify the column exists afterwards with a quick query in phpMyAdmin or the DB console:</p><p><strong>SQL:</strong></p><pre>DESCRIBE mdl_yourplugin;</pre><p>If the column is there, the upgrade ran. If not, check the Moodle error logs — either the version didn’t change or upgrade_mod_savepoint() is missing.</p><h3>What I Do Now</h3><p>I never touch the plugin database manually anymore — not even locally. If I need to add a column during development, I write the upgrade block first, bump the version, and run it through /admin/index.php the same way the live server will. That way, when I deploy, there&#39;s nothing to remember and nothing to run manually.</p><p>The few minutes it takes to write an upgrade block have saved me from a lot of late-night SSH sessions.</p><p><em>Originally published at </em><a href="https://makitweb.com/moodle-plugin-add-database-column-upgrade-php/"><em>https://makitweb.com</em></a><em> on August 9, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6163a7e5b90c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step-by-Step Guide: Installing CakePHP 4 Framework]]></title>
            <link>https://medium.com/@yssyogesh94/step-by-step-guide-installing-cakephp-4-framework-d3447fae7435?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3447fae7435</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mvc-frameworks]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[cakephp]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Sun, 01 Jan 2023 14:23:06 GMT</pubDate>
            <atom:updated>2023-06-21T05:28:55.750Z</atom:updated>
            <content:encoded><![CDATA[<p>CakePHP is a widely used PHP framework for small and large-scale projects. It is based on the MVC (Model View Controller) architecture which makes the development process easier if you are familiar with it.</p><p>It requires composer for installation.</p><p>In this tutorial, I show how you can install CakePHP 4 in your system.</p><p>I am assuming you have already installed composer. If not then you can follow this <a href="https://getcomposer.org/download/">link</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*ImigD3krrcq-Lfd-Yuqydw.jpeg" /></figure><h3>1. Server requirement</h3><ul><li>Minimum PHP version it requires is 7.4.</li><li>The following extensions need to be enabled — mbstring, intl, SimpleXML, and PDO.</li><li>It supports the following database storage engines -</li><li>MySQL (5.6 or higher)</li><li>MariaDB (5.6 or higher)</li><li>PostgreSQL (9.4 or higher)</li><li>Microsoft SQL Server (2012 or higher)</li><li>SQLite 3</li></ul><h3>2. Create a Project</h3><pre>composer create-project --prefer-dist cakephp/app:~4.0 cakephpproj</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EYw7Nqm94xAIKUk8.png" /></figure><h3>3. Start development server</h3><pre>bin/cake server</pre><ul><li>Navigate to the created project using the Command prompt if you are on windows or use the terminal if you are on Mac or Linux.</li><li>Run the following command for Mac and Linux -</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/0*lvd0IuQ8PLVuFlyb.png" /></figure><pre>cd bin/cake cake server</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/0*LwFkXNMtVLu7TgQq.png" /></figure><pre>bin/cake server -H 127.0.0.1 -p 3421</pre><p>or</p><pre>bin/cake server -H localhost -p 3421</pre><p>It will give the following output if the project runs successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5wNHBDNFxtzgy9PC.png" /></figure><h3>5. Conclusion</h3><p>I hope this tutorial helps you to set up your first CakePHP 4 project.</p><p><strong>If you found this tutorial helpful then don’t forget to share.</strong></p><p><em>Originally published at </em><a href="https://makitweb.com/how-to-install-cakephp-framework/"><em>https://makitweb.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3447fae7435" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Update Multiple Selected Records with PHP]]></title>
            <link>https://medium.com/@yssyogesh94/update-multiple-selected-records-with-php-ab24a9e9c9b9?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab24a9e9c9b9</guid>
            <category><![CDATA[jquery]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Mon, 23 Jul 2018 18:16:05 GMT</pubDate>
            <atom:updated>2018-08-04T05:57:02.269Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes its require to quickly modify multiple records and save it to the MySQL database table.</p><p>It makes easier to update records instead of updating one by one.</p><p>With <a href="https://makitweb.com/how-to-check-and-uncheck-all-using-jquery-and-javascript/">checkboxes</a>, enable multiple records selection from the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SJJkMpJD3A6LiYUMOPT5Ng.jpeg" /></figure><h3>1. Table structure</h3><p>Create users table.</p><pre>CREATE TABLE `users` ( <br>   `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, <br>   `username` varchar(80) DEFAULT NULL, <br>   `fname` varchar(50) NOT NULL, <br>   `lname` varchar(50) NOT NULL, <br>   `age` int(2) DEFAULT NULL, <br>   `salary` int(10) NOT NULL, <br>   `email` varchar(80) NOT NULL <br>) ENGINE=InnoDB DEFAULT CHARSET=utf8;</pre><h3>2. Configuration</h3><p>Create a config.php for database connection.</p><p><strong>Completed Code</strong></p><pre>&lt;?php </pre><pre>$host = &quot;localhost&quot;; /* Host name */ <br>$user = &quot;root&quot;; /* User */ <br>$password = &quot;&quot;; /* Password */ <br>$dbname = &quot;tutorial&quot;; /* Database name */ </pre><pre>$con = mysqli_connect($host, $user, $password,$dbname); // Check connection <br>if (!$con) { <br>   die(&quot;Connection failed: &quot; . mysqli_connect_error()); <br>}</pre><h3>3. Record List</h3><p>Create a &lt;form &gt; which contains submit button for update selected records and &lt;table &gt; to list records.</p><p>In the &lt;table &gt; add a checkbox in a &lt;th&gt; for check/uncheck all checkboxes.</p><p>Loop on fetched records and create &lt;tr &gt;. In first &lt;td&gt; add the checkbox for record selection. Set name=&#39;update[]&#39; and value=&#39;&lt;?= $id ?&gt;&#39;.</p><p><strong>jQuery Script –</strong></p><p>When checkAll checkbox state change then check if it is checked or not. If checked then set all records checkboxes checked property true otherwise false.</p><p>On the update checkbox click check if the total number of checkboxes equals to total checked checkboxes. If equal then set checkAll checkbox checked property true otherwise false.</p><p><strong>Completed Code</strong></p><pre>&lt;div class=&#39;container&#39;&gt; <br>   &lt;!-- Form --&gt; <br>   &lt;form method=&#39;post&#39; action=&#39;&#39;&gt; <br>      &lt;!-- Submit button --&gt; <br>      &lt;input type=&#39;submit&#39; value=&#39;Update Selected Records&#39; name=&#39;but_update&#39;&gt;&lt;br&gt;&lt;br&gt; </pre><pre>      &lt;!-- Record list --&gt; <br>      &lt;table border=&#39;1&#39; style=&#39;border-collapse: collapse;&#39; &gt; <br>        &lt;tr style=&#39;background: whitesmoke;&#39;&gt; <br>           &lt;!-- Check/Uncheck All--&gt; <br>           &lt;th&gt;&lt;input type=&#39;checkbox&#39; id=&#39;checkAll&#39; &gt; Check&lt;/th&gt; <br>           &lt;th&gt;Username&lt;/th&gt; <br>           &lt;th&gt;First Name&lt;/th&gt; <br>           &lt;th&gt;Last Name&lt;/th&gt; <br>           &lt;th&gt;Age&lt;/th&gt; <br>           &lt;th&gt;Salary&lt;/th&gt; <br>           &lt;th&gt;Email&lt;/th&gt; <br>        &lt;/tr&gt; <br>        &lt;?php <br>        $query = &quot;SELECT * FROM users&quot;; <br>        $result = mysqli_query($con,$query); <br>        while($row = mysqli_fetch_array($result) ){ <br>          $id = $row[&#39;id&#39;]; <br>          $username = $row[&#39;username&#39;]; <br>          $fname = $row[&#39;fname&#39;]; <br>          $lname = $row[&#39;lname&#39;]; <br>          $age = $row[&#39;age&#39;]; <br>          $salary = $row[&#39;salary&#39;]; <br>          $email = $row[&#39;email&#39;]; <br>        ?&gt; <br>        &lt;tr&gt; <br>           &lt;!-- Checkbox --&gt; <br>           &lt;td&gt;&lt;input type=&#39;checkbox&#39; name=&#39;update[]&#39; value=&#39;&lt;?= $id ?&gt;&#39; &gt;&lt;/td&gt; <br>           &lt;td&gt;&lt;?= $username ?&gt;&lt;/td&gt; <br>           &lt;td&gt;&lt;input type=&#39;text&#39; name=&#39;fname_&lt;?= $id ?&gt;&#39; value=&#39;&lt;?= $fname ?&gt;&#39; &gt;&lt;/td&gt; <br>           &lt;td&gt;&lt;input type=&#39;text&#39; name=&#39;lname_&lt;?= $id ?&gt;&#39; value=&#39;&lt;?= $lname ?&gt;&#39; &gt;&lt;/td&gt; <br>           &lt;td&gt;&lt;input type=&#39;number&#39; name=&#39;age_&lt;?= $id ?&gt;&#39; value=&#39;&lt;?= $age ?&gt;&#39; &gt;&lt;/td&gt; <br>           &lt;td&gt;&lt;input type=&#39;number&#39; name=&#39;salary_&lt;?= $id ?&gt;&#39; value=&#39;&lt;?= $salary ?&gt;&#39; &gt;&lt;/td&gt; <br>           &lt;td&gt;&lt;input type=&#39;text&#39; name=&#39;email_&lt;?= $id ?&gt;&#39; value=&#39;&lt;?= $email ?&gt;&#39; &gt;&lt;/td&gt; <br>         &lt;/tr&gt; <br>         &lt;?php <br>         } <br>         ?&gt; <br>      &lt;/table&gt; <br>   &lt;/form&gt; <br>&lt;/div&gt; </pre><pre>&lt;!-- Script --&gt; <br>&lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt; <br>&lt;script type=&quot;text/javascript&quot;&gt; <br>$(document).ready(function(){ <br>   <br>   // Check/Uncheck All <br>   $(&#39;#checkAll&#39;).change(function(){ <br>      if($(this).is(&#39;:checked&#39;)){      <br>         $(&#39;input[name=&quot;update[]&quot;]&#39;).prop(&#39;checked&#39;,true); <br>      }else{ <br>         $(&#39;input[name=&quot;update[]&quot;]&#39;).each(function(){<br>            $(this).prop(&#39;checked&#39;,false); <br>         }); <br>      } <br>   }); </pre><pre>   // Checkbox click <br>   $(&#39;input[name=&quot;update[]&quot;]&#39;).click(function(){ <br>      var total_checkboxes = $(&#39;input[name=&quot;update[]&quot;]&#39;).length; <br>      var total_checkboxes_checked = $(&#39;input[name=&quot;update[]&quot;]:checked&#39;).length; <br>      <br>      if(total_checkboxes_checked == total_checkboxes){<br>         $(&#39;#checkAll&#39;).prop(&#39;checked&#39;,true); <br>      }else{ <br>         $(&#39;#checkAll&#39;).prop(&#39;checked&#39;,false); <br>      } <br>    }); <br>}); <br>&lt;/script&gt;</pre><p>On &lt;form &gt; submit loop on selected checkboxes ids if selected.</p><p>Read the values from DOM elements according to $updateid. If all values entered then execute UPDATE query on $updateid.</p><p><strong>Completed Code</strong></p><pre>if(isset($_POST[&#39;but_update&#39;])){ <br>   if(isset($_POST[&#39;update&#39;])){ <br>      foreach($_POST[&#39;update&#39;] as $updateid){ <br>         $fname = $_POST[&#39;fname_&#39;.$updateid]; <br>         $lname = $_POST[&#39;lname_&#39;.$updateid]; <br>         $age = $_POST[&#39;age_&#39;.$updateid]; <br>         $salary = $_POST[&#39;salary_&#39;.$updateid]; <br>         $email = $_POST[&#39;email_&#39;.$updateid]; </pre><pre>         if($fname !=&#39;&#39; &amp;&amp; $lname !=&#39;&#39; &amp;&amp; $age &gt;0 &amp;&amp; $salary &gt;0 &amp;&amp; $email != &#39;&#39; ){ <br>            $updateUser = &quot;UPDATE users SET fname=&#39;&quot;.$fname.&quot;&#39;,lname=&#39;&quot;.$lname.&quot;&#39;, age=&quot;.$age.&quot;,salary=&quot;.$salary.&quot;,email=&#39;&quot;.$email.&quot;&#39; WHERE id=&quot;.$updateid; <br>            mysqli_query($con,$updateUser); <br>         } <br>      } <br>   } <br>}</pre><h3>5. Conclusion</h3><p>For multiple records, selection use checkbox elements and assign record id in the value attribute for accessing it on form submit for select and update records.</p><p>You can also use it to <a href="https://makitweb.com/delete-multiple-selected-records-with-php/">delete multiple</a> records.</p><p><em>Originally published at </em><a href="https://makitweb.com/update-multiple-selected-records-with-php/"><em>makitweb.com</em></a><em> on July 23, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab24a9e9c9b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create Custom Page Template in WordPress]]></title>
            <link>https://medium.com/@yssyogesh94/how-to-create-custom-page-template-in-wordpress-3b203c8ffd84?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b203c8ffd84</guid>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[cms]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Mon, 09 Jul 2018 18:09:47 GMT</pubDate>
            <atom:updated>2018-08-24T16:39:29.032Z</atom:updated>
            <content:encoded><![CDATA[<p>In WordPress, you can easily customize the page by editing the page.php file of the active theme. But the change will affect on all pages where no need of customization.</p><p>You can avoid this by creating the custom page template.</p><p>Using this you can design different-different layout for the pages and <a href="https://makitweb.com/how-to-display-different-sidebar-on-specific-pages-in-wordpress/">add extra</a> content to it without affecting regular pages on the site.</p><p>In this tutorial, I show how you can create and add the custom template to the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wu2__TcP43Jrx4GXkO5L7w.jpeg" /></figure><h3>1. Create Template file</h3><ul><li>Navigate to your active theme directory e.g. — twentyseventeen.</li><li>Here, create a new directory page-template to store template files.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/0*WhJglNhWLv4AVMhX" /></figure><ul><li>Create a new contactpage.php file inside page-template/ directory. You can rename the page to something meaningful name if you want.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/0*x8i97ujrwGxuSwT4" /></figure><p><strong>Add code</strong></p><p>To tell the WordPress that this file is a template file by adding the following code at the top and save it. Now the following template name visible on the WordPress Dashboard page template section.</p><pre>&lt;?php <br>/* Template Name: Contact page Template */</pre><p>Add some more code and create a contact form.</p><p><strong>Completed Code</strong></p><pre>&lt;?php <br>/* Template Name: Contact page Template */ </pre><pre>get_header(); <br>?&gt; </pre><pre>&lt;style&gt; <br>input[type=text], textarea { <br>   width: 100%; <br>   padding: 12px; <br>   border: 1px solid #ccc; <br>   margin-top: 6px; <br>   margin-bottom: 16px; <br>   resize: vertical; <br>} </pre><pre>input[type=submit] { <br>   background-color: #007eff; <br>   color: white; <br>   padding: 12px 20px; <br>   border: none; <br>   border-radius: 4px; <br>   cursor: pointer; <br>} </pre><pre>.container { <br>   border-radius: 5px; <br>   background-color: #f2f2f2; <br>   padding: 20px; <br>} <br>&lt;/style&gt; </pre><pre>&lt;div class=&quot;wrap&quot;&gt; <br>   &lt;h3&gt;Contact Us&lt;/h3&gt; <br>   &lt;div class=&quot;container&quot;&gt; <br>      &lt;form action=&quot;&quot;&gt; <br>        &lt;label for=&quot;fname&quot;&gt;First Name&lt;/label&gt; <br>        &lt;input type=&quot;text&quot; id=&quot;fname&quot; name=&quot;firstname&quot; placeholder=&quot;Your name..&quot;&gt;<br> <br>        &lt;label for=&quot;lname&quot;&gt;Last Name&lt;/label&gt; <br>        &lt;input type=&quot;text&quot; id=&quot;lname&quot; name=&quot;lastname&quot; placeholder=&quot;Your last name..&quot;&gt; </pre><pre>        &lt;label for=&quot;subject&quot;&gt;Subject&lt;/label&gt; <br>        &lt;textarea id=&quot;subject&quot; name=&quot;subject&quot; placeholder=&quot;Write something..&quot; style=&quot;height:200px&quot;&gt;&lt;/textarea&gt; </pre><pre>        &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt; <br>      &lt;/form&gt; <br>   &lt;/div&gt; <br>&lt;/div&gt;<br>&lt;!-- wrap --&gt; </pre><pre>&lt;?php <br>get_footer();</pre><h3>2. Apply Template</h3><ul><li>Login to Admin Dashboard and navigate to Pages-&gt;Add new or Edit an existing page.</li><li>Template list display in Page Attributes section.</li><li>Select Contact page Template option from the dropdown.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7i6MfzB2jEnR-wVK" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CpiVR6fBZ9xjStKK" /></figure><h3>3. Conclusion</h3><p>It is better to use custom templates if you only want to customize specific pages. You can create separate page-template for multiple pages.</p><p>To apply you need navigate to Pages or create a new from Dashboard and select the template.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fea3241%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fea3241%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href">https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href</a></iframe><p><em>Originally published at </em><a href="https://makitweb.com/how-to-create-custom-page-template-in-wordpress/"><em>makitweb.com</em></a><em> on July 9, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b203c8ffd84" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Copy text to Clipboard using vue-clipboard2 — Vue.js]]></title>
            <link>https://medium.com/@yssyogesh94/copy-text-to-clipboard-using-vue-clipboard2-vue-js-e609795fe107?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e609795fe107</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[plugins]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Mon, 23 Apr 2018 15:47:58 GMT</pubDate>
            <atom:updated>2020-06-15T20:35:13.092Z</atom:updated>
            <content:encoded><![CDATA[<p>Copying the selected text from the webpage or input HTML element is easy with the keyboard shortcut CTRL+C and context menu.</p><p>To make it little easier for the user you can add a button.</p><p>For copy text to clipboard in Vue.js you can use vue-clipboard2 package.</p><p>In this tutorial, I show how you can <a href="https://makitweb.com/how-to-copying-content-to-the-clipboard-with-javascript/">copy text</a> from HTML element on button click to the clipboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Szylxy12v9D_pfeIpXfGSg.jpeg" /></figure><h3>1. Download Clipboard.js</h3><ul><li>Download package from <a href="https://github.com/Inndy/vue-clipboard2">GitHub</a> and extract in your project directory.</li><li>Include vue-clipboard.min.js script with vue.js in the &lt;head&gt; section.</li></ul><pre>&lt;script src=&quot;vue.js&quot;&gt;&lt;/script&gt; <br>&lt;script src=&quot;vue-clipboard2-master/dist/vue-clipboard.min.js&quot;&gt;&lt;/script&gt;</pre><h3>2. HTML</h3><p>Create two &lt;textarea&gt; and a button.</p><p>The first textarea for inputting some text and the second textarea to display the copied text when a button gets clicked.</p><p>In the button define 3 attributes –</p><ul><li><strong>v-clipboard:copy </strong>— Here, passed the model name message from where to copy text.</li><li><strong>v-clipboard:success </strong>— Pass method name onCopy. This called when text copied successfully.</li><li><strong>v-clipboard:error </strong>— Pass method name onError. This called when it failed to copy text.</li></ul><p><strong>Completed Code</strong></p><pre>&lt;div id=&quot;app&quot;&gt; <br>   &lt;textarea v-model=&#39;message&#39;&gt;&lt;/textarea&gt; <br>   &lt;button type=&quot;button&quot; v-clipboard:copy=&quot;message&quot; v-clipboard:success=&quot;onCopy&quot; v-clipboard:error=&quot;onError&quot;&gt;Copy&lt;/button&gt; <br>   &lt;br/&gt; <br>   Copied Text: &lt;br/&gt;<br>   &lt;textarea v-model=&#39;copiedText&#39;&gt;&lt;/textarea&gt; <br>&lt;/div&gt;</pre><h3>3. Script</h3><p>Create two data variables — message, and copiedText.</p><p>Define two methods –</p><ul><li><strong>onCopy </strong>— Called when copy text to the clipboard. Assign e.text to this.copiedText.</li><li><strong>onError </strong>— Called when failed to copy text.</li></ul><p><strong>Completed Code</strong></p><pre>new Vue({ <br>  el: &#39;#app&#39;, <br>  data:{ <br>    message: &#39;&#39;, <br>    copiedText: &#39;&#39; <br>  }, <br>  methods: { <br>    onCopy: function (e) { <br>      this.copiedText = e.text; <br>    }, <br>    onError: function (e) { <br>      console.log(&#39;Failed to copy texts&#39;) <br>    } <br>  } <br>})</pre><h3>4. Conclusion</h3><p>With vue-clipboard2.js package you can easily copy text to <a href="http://makitweb.com/cut-copy-text-to-clipboard-with-ngclipboard-in-angularjs/">clipboard</a> on the button click. It works the same as copying text by pressing CTRL+C from the keyboard.</p><p><strong>You can view working demo of example </strong><a href="https://makitweb.com/copy-text-to-clipboard-using-vue-clipboard2-vue-js/"><strong>here</strong></a><strong>.</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkD9zMUUYzWM&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkD9zMUUYzWM&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FkD9zMUUYzWM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/66bc50df629ac4f923ef5dcd1c512b53/href">https://medium.com/media/66bc50df629ac4f923ef5dcd1c512b53/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fea3241%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fea3241%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href">https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href</a></iframe><p><em>Originally published at </em><a href="https://makitweb.com/copy-text-to-clipboard-using-vue-clipboard2-vue-js/"><em>makitweb.com</em></a><em> on April 23, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e609795fe107" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Check Username Availability with Vue.js and PHP]]></title>
            <link>https://medium.com/@yssyogesh94/check-username-availability-with-vue-js-and-php-bf2575173ff6?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf2575173ff6</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[vuejs]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Mon, 16 Apr 2018 06:36:05 GMT</pubDate>
            <atom:updated>2018-08-24T18:03:59.933Z</atom:updated>
            <content:encoded><![CDATA[<p>Live username availability checking on the registration page is the common feature in most of the website.</p><p>This will notify the user whether the username is already been taken or not before submitting.</p><p>To do this require <a href="https://makitweb.com/fetch-records-from-mysql-database-with-vue-js-and-php/">AJAX</a>.</p><p>Send a request to check the username on the bases of response perform the action.</p><p>In this tutorial, I show how you can check username availability using Vue.js and PHP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9iTg9Rf-e2MseY9huHYteg.jpeg" /></figure><h3>1. Table structure</h3><p>I am using users table in the example.</p><pre>CREATE TABLE `users` ( <br>   `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, <br>   `username` varchar(80) NOT NULL, <br>   `name` varchar(80) NOT NULL, <br>   `password` varchar(80) NOT NULL <br>) ENGINE=InnoDB DEFAULT CHARSET=latin1;</pre><h3>2. Configuration</h3><p>Create a new config.php file.</p><p><strong>Completed Code</strong></p><pre>&lt;?php <br>$host = &quot;localhost&quot;; /* Host name */ <br>$user = &quot;root&quot;; /* User */ <br>$password = &quot;&quot;; /* Password */ <br>$dbname = &quot;tutorial&quot;; /* Database name */ </pre><pre>// Create connection <br>$con = mysqli_connect($host, $user, $password,$dbname); </pre><pre>// Check connection <br>if (!$con) { <br>  die(&quot;Connection failed: &quot; . mysqli_connect_error()); <br>}</pre><h3>3. HTML</h3><p>Create a textbox and &lt;span&gt; to show message.</p><p>In the textbox added v-model=&#39;username&#39; and @keyup=&#39;checkUsername()&#39;.</p><p>To display the message in &lt;span&gt; added {{responseMessage}} and v-bind:class to change class according to isAvailable value.</p><p><strong>Completed Code</strong></p><pre>&lt;style &gt; <br>.available{ <br>  color: green; <br>} <br>.notavailable{ <br>  color: red; <br>} <br>&lt;/style&gt; </pre><pre>&lt;div id=&#39;myapp&#39;&gt; <br>   Enter username : &lt;input type=&#39;text&#39; v-model=&#39;username&#39; @keyup=&#39;checkUsername()&#39;&gt; <br>   &lt;span v-bind:class=&quot;[isAvailable ? &#39;notavailable&#39; : &#39;available&#39;]&quot; &gt;{{responseMessage}}&lt;/span&gt; <br>&lt;/div&gt;</pre><h3>4. PHP</h3><p>Create a ajaxfile.php file.</p><p>Check username in the users table. If record found then assign 1 to $found.</p><p>Return $found.</p><p><strong>Completed Code</strong></p><pre>&lt;?php <br>include &quot;config.php&quot;; <br>$username = &quot;&quot;; <br>$found = 0;<br> <br>if(isset($_GET[&#39;username&#39;])){ <br>  $username = mysqli_escape_string($con,$_GET[&#39;username&#39;]); </pre><pre>  // Check username <br>  $result = mysqli_query($con,&quot;select * from users WHERE username=&#39;&quot;.$username.&quot;&#39;&quot;); <br>  <br>  if(mysqli_num_rows($result) &gt; 0){ <br>    $found = 1; <br>  } <br>} </pre><pre>echo $found;</pre><h3>5. Script</h3><p>Create 3 data variable — username, isAvaialble, and responseMessage.</p><p>Here, isAvailable is used to toggle &lt;span&gt; class and the responseMessage to display a message.</p><p>Define a checkUsername method.</p><p>Send GET request where pass username: username. On successful callback assign app.isAvailable = response.data.</p><p>If response.data == 0 then assign app.responseMessage = &quot;Username is Available.&quot; otherwise app.responseMessage = &quot;Username is not Available.&quot;.</p><p><strong>Completed Code</strong></p><pre>var app = new Vue({ <br>  el: &#39;#myapp&#39;, <br>  data: { <br>    username: &#39;&#39;, <br>    isAvailable: 0, <br>    responseMessage: &#39;&#39; <br>  }, <br>  methods: { <br>    checkUsername: function(){ <br>      var username = this.username.trim(); <br>      if(username != &#39;&#39;){ <br>        axios.get(&#39;ajaxfile.php&#39;, { <br>           params: { <br>             username: username <br>           } <br>        }).then(function (response) { <br>           app.isAvailable = response.data; <br>           if(response.data == 0){ <br>             app.responseMessage = &quot;Username is Available.&quot;; <br>           }else{ <br>             app.responseMessage = &quot;Username is not Available.&quot;; <br>           } <br>        }).catch(function (error) { <br>           console.log(error); <br>        }); <br>      }else{ <br>         this.responseMessage = &quot;&quot;; <br>      } <br>     } <br>  } <br>})</pre><h3>6. Conclusion</h3><p>It is better to prevent the user from selecting existing username before submitting the form.</p><p>Also, check the username availability while <a href="https://makitweb.com/insert-update-delete-records-from-mysql-with-vue-js/">inserting </a>the record.</p><p><strong>You can view working demo of tutorial example </strong><a href="https://makitweb.com/check-username-availability-with-vue-js-and-php/"><strong>here</strong></a><strong>.</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fea3241%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fea3241%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href">https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href</a></iframe><p><em>Originally published at </em><a href="https://makitweb.com/check-username-availability-with-vue-js-and-php/"><em>makitweb.com</em></a><em> on April 16, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf2575173ff6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fetch records from MySQL Database with Vue.js and PHP]]></title>
            <link>https://medium.com/@yssyogesh94/fetch-records-from-mysql-database-with-vue-js-and-php-a6a80539f07?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6a80539f07</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[vuejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Mon, 02 Apr 2018 15:10:36 GMT</pubDate>
            <atom:updated>2020-06-11T20:24:57.782Z</atom:updated>
            <content:encoded><![CDATA[<p>Data selection is one of the basic requirements when creating a dynamic website.</p><p>Mainly data is fetched from the database on page refresh but for without page refresh require to send AJAX request.</p><p>I am using the Axios package to send AJAX request.</p><p>In this tutorial, I show how you can fetch records from MySQL database using Vue.js and PHP with the Axios package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o4zRTi-aPuvcZh59L2YcZw.jpeg" /></figure><h3>1. Table structure</h3><p>I am using users table in the example.</p><pre>CREATE TABLE `users` ( <br>   `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT, <br>   `username` varchar(100) NOT NULL, <br>   `name` varchar(100) NOT NULL, <br>   `email` varchar(100) NOT NULL <br>) ENGINE=InnoDB DEFAULT CHARSET=latin1;</pre><h3>2. Configuration</h3><p>Create a new config.php file.</p><p><strong>Completed Code</strong></p><pre>&lt;?php <br>$host = &quot;localhost&quot;; /* Host name */ <br>$user = &quot;root&quot;; /* User */ <br>$password = &quot;&quot;; /* Password */ <br>$dbname = &quot;tutorial&quot;; /* Database name */ </pre><pre>$con = mysqli_connect($host, $user, $password,$dbname); </pre><pre>// Check connection <br>if (!$con) { <br>   die(&quot;Connection failed: &quot; . mysqli_connect_error()); <br>}</pre><h3>3. Download &amp; Include</h3><ul><li>Download Axios package from <a href="https://github.com/axios/axios">GitHub</a>. or you can also use CDN (https://unpkg.com/axios/dist/axios.min.js).</li><li>Now, include axios.min.js with vue.js in the &lt;head&gt; section.</li></ul><pre>&lt;script src=&quot;vue.js&quot;&gt;&lt;/script&gt; <br>&lt;script src=&quot;https://unpkg.com/axios/dist/axios.min.js&quot;&gt;&lt;/script&gt;</pre><h3>4. HTML</h3><p>Create two buttons and a textbox.</p><p>On the first button define @click=&#39;allRecords()&#39; and on the second define @click=&#39;recordByID()&#39; events.</p><p>Add v-model=&#39;userid&#39; in the textbox.</p><p>Use v-for=&#39;user in users&#39; on &lt;tr&gt; to list records.</p><ul><li>The first button is used to send GET request without a parameter.</li><li>The second button is used to send GET request with parameters.</li></ul><p><strong>Completed Code</strong></p><pre>&lt;div id=&#39;myapp&#39;&gt; <br>   &lt;!-- Select All records --&gt; <br>   &lt;input type=&#39;button&#39; @click=&#39;allRecords()&#39; value=&#39;Select All users&#39;&gt; <br>   &lt;br&gt;&lt;br&gt; <br>   &lt;!-- Select record by ID --&gt; <br>   &lt;input type=&#39;text&#39; v-model=&#39;userid&#39; placeholder=&quot;Enter Userid between 1 - 24&quot;&gt; <br>   &lt;input type=&#39;button&#39; @click=&#39;recordByID()&#39; value=&#39;Select user by ID&#39;&gt; <br>   &lt;br&gt;&lt;br&gt; <br>   &lt;!-- List records --&gt; <br>   &lt;table border=&#39;1&#39; width=&#39;80%&#39; style=&#39;border-collapse: collapse;&#39;&gt;    <br>     &lt;tr&gt; <br>       &lt;th&gt;Username&lt;/th&gt; <br>       &lt;th&gt;Name&lt;/th&gt; <br>       &lt;th&gt;Email&lt;/th&gt; <br>     &lt;/tr&gt; <br>     &lt;tr v-for=&#39;user in users&#39;&gt; <br>       &lt;td&gt;{{ user.username }}&lt;/td&gt; <br>       &lt;td&gt;{{ user.name }}&lt;/td&gt; <br>       &lt;td&gt;{{ user.email }}&lt;/td&gt; <br>     &lt;/tr&gt; <br>   &lt;/table&gt; <br>&lt;/div&gt;</pre><h3>5. PHP</h3><p>Create a new ajaxfile.php.</p><p>Fetch records from the users table and initialize $response Array.</p><p>Assign &quot; id =&quot;.$_GET[&#39;userid&#39;] to $where if $_GET[&#39;userid&#39;] is passed.</p><p>Return JSON response.</p><p><strong>Completed Code</strong></p><pre>&lt;?php </pre><pre>include &quot;config.php&quot;; </pre><pre>$condition = &quot;1&quot;; </pre><pre>if(isset($_GET[&#39;userid&#39;])){ <br>  $condition = &quot; id=&quot;.$_GET[&#39;userid&#39;]; <br>} </pre><pre>$userData = mysqli_query($con,&quot;select * from users WHERE &quot;.$condition); </pre><pre>$response = array(); </pre><pre>while($row = mysqli_fetch_assoc($userData)){ <br>  $response[] = $row; <br>} </pre><pre>echo json_encode($response); exit;</pre><h3>6. Script</h3><p><strong>Syntax — Axios GET request without parameter –</strong></p><pre>axios.get(&#39;path&#39;).then(function(response){ <br>  // Handle response <br>}).catch(function(error){ <br>   // Error handling <br>});</pre><p><strong>Syntax — Axios GET request with parameter –</strong></p><pre>axios.get(&#39;path&#39;,{ <br>   params:{ <br>     parameter1: value, <br>     parameter2: value, <br>     .... <br>   } <br>}).then(function(response){ <br>   // Handle response <br>}).catch(function(error){ <br>   // Error handling <br>});</pre><p>OR</p><pre>axios.get(&#39;path?variable1=value1&amp;variable2=value2&amp;...&#39;) .then(function(response){ <br>   // Handle response <br>}).catch(function(error){ <br>   // Error handling <br>});</pre><p>Define two variable users and userid.</p><p>Define two methods –</p><ul><li><strong>allRecords </strong>— Send AJAX request to fetch all records and assign response.data to app.users. Here, app.users pointing to defined data variable.</li><li><strong>recordByID — </strong>Pass the textbox value this.userid in params: {<br> userid: this.userid }. Assign response.data in app.users on successful callback.</li></ul><p><strong>Completed Code</strong></p><pre>var app = new Vue({ <br>  el: &#39;#myapp&#39;, <br>  data: { <br>    users: &quot;&quot;, <br>    userid: 0 <br>  }, <br>  methods: { <br>    allRecords: function(){ <br>      axios.get(&#39;ajaxfile.php&#39;).then(function (response) { <br>        app.users = response.data; <br>      }) .catch(function (error) { <br>        console.log(error); <br>      }); <br>    }, <br>    recordByID: function(){ <br>      if(this.userid &gt; 0){ <br>        axios.get(&#39;ajaxfile.php&#39;, { <br>          params: { <br>            userid: this.userid <br>          } <br>        }).then(function (response) { <br>          app.users = response.data; <br>        }).catch(function (error) { <br>          console.log(error); <br>        }); <br>      } <br>    } <br>  } <br>})</pre><h3>7. Conclusion</h3><p>Use params option to pass data to AJAX request or you can directly pass it with the path.</p><p>You can view the working demo <a href="https://makitweb.com/fetch-records-from-mysql-database-with-vue-js-and-php/">here</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8QndJWGsz4s%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8QndJWGsz4s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8QndJWGsz4s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/94ab4db8b04a9151b63e2631ed78d9be/href">https://medium.com/media/94ab4db8b04a9151b63e2631ed78d9be/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fea3241%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fea3241%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href">https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href</a></iframe><p><em>Originally published at </em><a href="http://makitweb.com/fetch-records-from-mysql-database-with-vue-js-and-php/"><em>makitweb.com</em></a><em> on April 2, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6a80539f07" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to install Laravel Framework in Windows]]></title>
            <link>https://medium.com/@yssyogesh94/how-to-install-laravel-framework-in-windows-cfe43932330?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfe43932330</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Thu, 29 Mar 2018 03:22:36 GMT</pubDate>
            <atom:updated>2018-04-14T12:31:14.160Z</atom:updated>
            <content:encoded><![CDATA[<p>Laravel is a free open-source web development framework which follows Model view controller (MVC) architectural pattern.</p><p>It uses Composer to manage its dependencies.</p><p>In this tutorial, I show step by step how you can install Laravel on your Windows system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TLYcwFJUvas15rgQqd-keA.jpeg" /></figure><h3>1. System Requirement</h3><ul><li>PHP &gt;= 7.1.3</li><li>OpenSSL PHP Extension</li><li>PDO PHP Extension</li><li>Mbstring PHP Extension</li><li>Tokenizer PHP Extension</li><li>XML PHP Extension</li><li>Ctype PHP Extension</li><li>JSON PHP Extension</li></ul><h3>2. Download and Install Composer</h3><ul><li>Download Composer-Setup.exe from <a href="https://getcomposer.org/download/">here</a>.</li><li>Run the downloaded file.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*Ks8w_njor5cHqoRF." /></figure><ul><li>Click Next.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*1cjKj-9fVaeTUbSV." /></figure><ul><li>Browser the php.exe location and Click Next.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/0*sYMZ3wUx-p0ZZX4S." /></figure><ul><li>Click Next.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/0*ajWxLkOsnQczTUnE." /></figure><ul><li>Click Install.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*Kb79KwSNbr2MHP27." /></figure><ul><li>Finish.</li></ul><h3>3. Create Project</h3><ul><li>Open Command Prompt and navigate to xampp/htdocs/ directory.</li><li>Execute composer create-project laravel/laravel {project-name}. Enter the name of your project in the place of {project-name} e.g. composer create-project laravel/laravel laravel_project.</li><li>This will download and install the latest version of Laravel.</li></ul><pre>F:\&gt;cd xampp\htdocs <br>F:\xampp\htdocs&gt;composer create-project laravel/laravel laravel_project</pre><p>Directory structure after installation –</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/0*kKZgO1kvl6MCyFYR." /></figure><h3>4. Start Development Server</h3><ul><li>Open Command Prompt.</li><li>Navigate to the newly created project directory (laravel_project).</li><li>Run php artisan serve. This will start the development server.</li></ul><pre>F:\xampp\htdocs&gt;cd laravel_project F:\xampp\htdocs\laravel_project&gt;php artisan serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/0*-Ohaes8jf0SY7A_4." /></figure><p><strong>Change Port</strong></p><p>Add --port={port-number} to php artisan serve command.</p><pre>F:\xampp\htdocs&gt;cd laravel_project F:\xampp\htdocs\laravel_project&gt;php artisan serve --port=3421</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/0*QZ2e5ULBDrtzc1qO." /></figure><h3>5. Output</h3><p>In browser run localhost:8000 if have not set port otherwise run localhost:3421 with your set port number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BAagJGpFj0-OA6Oe." /></figure><h3>6. Conclusion</h3><p>You need to install Composer on your system to create a Laravel project. Use php artisan serve command to run the development server.</p><p><em>Originally published at </em><a href="http://makitweb.com/how-to-install-laravel-framework-in-windows/"><em>makitweb.com</em></a><em> on March 29, 2018.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fea3241%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fea3241%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href">https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfe43932330" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create custom 404 Error page in CodeIgniter]]></title>
            <link>https://medium.com/@yssyogesh94/create-custom-404-error-page-in-codeigniter-7b8e973e1f46?source=rss-781e0089d42c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b8e973e1f46</guid>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[codeigniter]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Yogesh Singh]]></dc:creator>
            <pubDate>Mon, 26 Mar 2018 03:21:33 GMT</pubDate>
            <atom:updated>2018-04-25T19:20:09.677Z</atom:updated>
            <content:encoded><![CDATA[<p>CodeIgniter displays a simple 404 error page whenever the user navigates to a broken link.</p><p>You can easily customize it and make more user-friendly for the user.</p><p>In this tutorial, I show how you can create custom 404 error page in CodeIgniter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5KJJ-fibJgeev3LqyeDAg.jpeg" /></figure><h3>1. Route</h3><p>Open application/config/route.php file.</p><p>Edit –</p><pre>$route[&#39;404_override&#39;] = &#39;Custom404&#39;;</pre><p>Here, Custom404 is a name of the controller.</p><h3>2. Controller</h3><p>Create a new Custom404.php file in application/controllers/ directory.</p><p>In index() method execute $this-&gt;output-&gt;set_status_header(&#39;404&#39;); and load error404 view.</p><p><strong>Completed Code</strong></p><pre>&lt;?php <br>defined(&#39;BASEPATH&#39;) OR exit(&#39;No direct script access allowed&#39;); </pre><pre>class Custom404 extends CI_Controller { </pre><pre>   public function __construct() { <br>      parent::__construct(); // load base_url <br>      $this-&gt;load-&gt;helper(&#39;url&#39;); <br>   }<br> <br>   public function index(){ <br>      $this-&gt;output-&gt;set_status_header(&#39;404&#39;); <br>      $this-&gt;load-&gt;view(&#39;error404&#39;); <br>   } <br>}</pre><h3>3. View</h3><p>Create a error404.php file in application/views/ directory.</p><p>Here, I created a simple 404 error page.</p><p><strong>Completed Code</strong></p><pre>&lt;!doctype html&gt; <br>&lt;html&gt; <br>  &lt;head&gt; <br>    &lt;title&gt;404 Page Not Found&lt;/title&gt; <br>    &lt;style&gt; <br>      body{ <br>        width: 99%; height: 100%; <br>        background-color: mediumturquoise; <br>        color: white; <br>        font-family: sans-serif; <br>      } <br>      div { <br>        position: absolute; <br>        width: 400px; <br>        height: 300px; <br>        z-index: 15; <br>        top: 45%; <br>        left: 50%; <br>        margin: -100px 0 0 -200px; <br>        text-align: center; <br>      } <br>      h1,h2{ <br>        text-align: center; <br>      } <br>      h1{ <br>        font-size: 60px; <br>        margin-bottom: 10px; <br>        border-bottom: 1px solid white; <br>        padding-bottom: 10px; <br>      } <br>      h2{ <br>        margin-bottom: 40px; <br>      } <br>      a{ <br>        margin-top:10px; <br>        text-decoration: none; <br>        padding: 10px 25px; <br>        background-color: ghostwhite; <br>        color: black; <br>        margin-top: 20px; <br>      } <br>    &lt;/style&gt; <br>  &lt;/head&gt; <br>  &lt;body&gt; <br>     &lt;div&gt; <br>       &lt;h1&gt;404&lt;/h1&gt; <br>       &lt;h2&gt;Page not found&lt;/h2&gt; <br>       &lt;a href=&#39;&lt;?= base_url(); ?&gt;&#39; &gt;Back to Homepage&lt;/a&gt; <br>     &lt;/div&gt; <br>  &lt;/body&gt; <br>&lt;/html&gt;</pre><h3>4. Output</h3><p>404 Error page looks like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HxBqi8EJxZxUN-fP." /></figure><h3>5. Conclusion</h3><p>You need to create a controller from where load custom 404 view page. Assign Controller name to $route[&#39;404_override&#39;] in route.php.</p><p><em>Originally published at </em><a href="http://makitweb.com/create-custom-404-error-page-in-codeigniter/"><em>makitweb.com</em></a><em> on March 26, 2018.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fea3241%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fea3241%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href">https://medium.com/media/b760f2eb81a374daf7af8773e36d44ee/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b8e973e1f46" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>