<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdulbaki Suraj</title>
    <description>The latest articles on DEV Community by Abdulbaki Suraj (@codelikesuraj).</description>
    <link>https://dev.to/codelikesuraj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F780411%2Fad957ae3-72da-444c-95cc-ca18566b5882.jpeg</url>
      <title>DEV Community: Abdulbaki Suraj</title>
      <link>https://dev.to/codelikesuraj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codelikesuraj"/>
    <language>en</language>
    <item>
      <title>Send PHP errors to Telegram with lograh-php package</title>
      <dc:creator>Abdulbaki Suraj</dc:creator>
      <pubDate>Wed, 20 Mar 2024 14:24:41 +0000</pubDate>
      <link>https://dev.to/codelikesuraj/send-php-errors-to-telegram-with-lograh-php-package-3e7e</link>
      <guid>https://dev.to/codelikesuraj/send-php-errors-to-telegram-with-lograh-php-package-3e7e</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Error handling in PHP
&lt;/h3&gt;

&lt;p&gt;Error handling is one of the critical aspects of any PHP application. When unexpected situations occur during program execution, proper error management ensures that the application can easily handle these scenarios without crashing or producing undesirable outcomes.&lt;/p&gt;

&lt;p&gt;In PHP, the ‘try’ and ‘catch’ constructs are fundamental components of the language’s exception handling mechanism. These basically tells the source code to ‘try’ and execute a block of code and if an exception occurs, it ‘catch’es it and any action can be taken in the ‘catch’ block without stopping the running process.&lt;/p&gt;

&lt;p&gt;Here’s a basic example of a try-catch block in action.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
 &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// run piece of code that may throw an exception&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;\Throwable&lt;/span&gt; &lt;span class="nv"&gt;$exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// log or process the exception&lt;/span&gt;
  &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nc"&gt;Caught&lt;/span&gt; &lt;span class="n"&gt;an&lt;/span&gt; &lt;span class="n"&gt;exception&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$exception&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
 &lt;span class="c1"&gt;// do some other things&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have a ‘try’ block that might throw an exception and if one were to occur, it is caught in the corresponding ‘catch’ block and you can access any information about the exception from the ‘$exception’ variable.&lt;/p&gt;

&lt;h3&gt;
  
  
  The lograh-php package
&lt;/h3&gt;

&lt;p&gt;Let’s say we have a scenario where you have a critical process running in your PHP project and you would like to be notified outside of your app as soon as an exception occurs. There are a lot of packages and third-party tools out there that can be used to implement, but a host of them are either too complicated to set up, have a lot of dependencies (which can impact performance) or cost you to use.&lt;/p&gt;

&lt;p&gt;The lograh-php package is a very light-weight solution for this as it easily utilizes Telegram’s popular Bots API, allowing you to send information about these exceptions directly to any dedicated chat, group or channel on your Telegram account.&lt;/p&gt;




&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;Before you can use this package, you need a Telegram Bot setup on your account. What we need here is the API Key generated after creating your Bot and your chat, group or channel ID.&lt;/p&gt;

&lt;h3&gt;
  
  
  Obtain your bot token
&lt;/h3&gt;

&lt;p&gt;Obtaining your Bot token is a pretty straightforward process in the steps listed below.&lt;/p&gt;

&lt;p&gt;Follow this link &lt;a href="https://t.me/botfather"&gt;https://t.me/botfather&lt;/a&gt; to interact with the BotFather to generate a new Telegram bot.&lt;/p&gt;

&lt;p&gt;Once it opens up, if not already selected, type in the command ‘/newbot’ in the message box or select the option from the side menu and follow through with the prompts as shown in the screenshot below.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m3q0yltlh22mmqauwip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3m3q0yltlh22mmqauwip.png" alt="screenshot of how to create your Telegram bot and get generate an API token" width="800" height="810"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the token and keep in a secure place.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59bzd2vwenqdm2dubary.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F59bzd2vwenqdm2dubary.png" alt="screenshot of the section with the API token" width="800" height="115"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then click on your bot link.&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcusqs80jku01v0q1glo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcusqs80jku01v0q1glo.png" alt="screenshot of the section with the Telegram bot link" width="800" height="96"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This takes you to a chat window with your window, then you click “Start” button at the bottom of the screen or enter the “/start” command in the message box.&lt;/p&gt;
&lt;h3&gt;
  
  
  Get your chat ID
&lt;/h3&gt;

&lt;p&gt;Your chat ID is used to identify the chat that the logs would be sent to. This could be your direct inbox, a public/private that you have admin access to. In this scenario, we will be sending the logs directly to your chat.&lt;/p&gt;

&lt;p&gt;Follow this link &lt;a href="https://t.me/userinfobot"&gt;https://t.me/userinfobot&lt;/a&gt; to interact with the “userinfobot” to display your user info when you forward a message to it.&lt;/p&gt;

&lt;p&gt;Click the “start” button on the bottom of the screen or type in the command “/start”.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftrac359a12i3sa0j7cym.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftrac359a12i3sa0j7cym.png" alt="screenshot of user details after using the start prompt" width="550" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This should show your user details.&lt;/p&gt;

&lt;p&gt;Copy your ID and also keep in a secure place for later.&lt;/p&gt;
&lt;h3&gt;
  
  
  Include the lograh-php package
&lt;/h3&gt;

&lt;p&gt;If your PHP project is setup with composer, you can easily import the package by running the command below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;composer require codelikesuraj/lograh-php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3a7a99cp0hsh9epnzp5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg3a7a99cp0hsh9epnzp5.png" alt="screenshot of terminal process after adding the lograh-php package to the package" width="800" height="320"&gt;&lt;/a&gt;&lt;br&gt;
Or you can copy/clone the project from github, &lt;a href="https://github.com/codelikesuraj/lograh-php"&gt;https://github.com/codelikesuraj/lograh-php&lt;/a&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;We are going to be using a skeleton project I created specifically for this tutorial, you can check out the source-code here &lt;a href="https://github.com/codelikesuraj/lograh-tut"&gt;https://github.com/codelikesuraj/lograh-tut&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Create an index.php file in the root of the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;index.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the index.php file, initialize an instance of the LograhPHP\Logger class with your project name, bot token and chat ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;require_once&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"vendor/autoload.php"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nv"&gt;$logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Codelikesuraj\LograhPHP\Logger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;appName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Lograh Tutorial"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;botToken&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"api_key_generated_from_your_telegram_bot"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;chatId&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"id_of_your_telegram_chat_or_channel_or_group"&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mf"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add this simple try-catch block just below it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="mf"&gt;...&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;\Exception&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"I am an error from Lograh-tut"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;\Throwable&lt;/span&gt; &lt;span class="nv"&gt;$exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// send exception to Telegram using any&lt;/span&gt;
    &lt;span class="c1"&gt;// of the following methods&lt;/span&gt;
    &lt;span class="nv"&gt;$logger&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;reportAsText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$exception&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now run the code and you should receive a message on your telegram that looks something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php index.php
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwn1xcnx6hd35h68g11a5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwn1xcnx6hd35h68g11a5.png" alt="screenshot of message when an exception is caught and the 'reportAsText' method is used" width="540" height="260"&gt;&lt;/a&gt;&lt;br&gt;
Also, for a JSON style message, you can use either use the ‘reportAsJson()’ or ‘reportAsJsonWithStackTrace()’ method which as the name suggests sends the report as a JSON without and with the stack trace respectively.&lt;/p&gt;

&lt;p&gt;Here’s a sample of what those implementations might look like.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="mf"&gt;...&lt;/span&gt;
&lt;span class="nv"&gt;$logger&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;reportAsJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$exception&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mf"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjus3m0u5lhv1ioar61br.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjus3m0u5lhv1ioar61br.png" alt="screenshot of message when 'reportAsJson' method is used" width="735" height="396"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="mf"&gt;...&lt;/span&gt;
&lt;span class="nv"&gt;$logger&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;reportAsJsonWithStackTrace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$exception&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="mf"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fle7g67xbgfsz40xgl5qd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fle7g67xbgfsz40xgl5qd.png" alt="screenshot of message when 'reportAsJsonWithStackTrace' method is used" width="753" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Getting started as a backend developer: A beginner’s guide</title>
      <dc:creator>Abdulbaki Suraj</dc:creator>
      <pubDate>Sun, 10 Mar 2024 10:03:30 +0000</pubDate>
      <link>https://dev.to/codelikesuraj/getting-started-as-a-backend-developer-a-beginners-guide-4kpg</link>
      <guid>https://dev.to/codelikesuraj/getting-started-as-a-backend-developer-a-beginners-guide-4kpg</guid>
      <description>&lt;p&gt;Getting started in anything these days is usually hard for beginners than people actually realize. With a huge number of resources on the web and easy accessibility from anywhere in the world, navigating the right path can be an exhausting task.&lt;/p&gt;

&lt;p&gt;In this post, I try to get you acquainted with the backend development space, a guide on what to learn and a few lists of resources to get you started.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Backend Development?
&lt;/h2&gt;

&lt;p&gt;Backend is a term used to describe the unseen activities that happen in the background whenever any action is taken on a website. Those actions could include signing in, creating an account, accessing resources on a web application, purchasing an item in an online store and so on.&lt;/p&gt;

&lt;p&gt;Backend development also sometimes referred to as server-side development involves creating logic and code that interacts with a database or storage media stored on a server, a programming interface that exchanges information between the user on the frontend (the part of the website the user can see and interact with) and the database and then output necessary information back to the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who is a Backend Developer?
&lt;/h2&gt;

&lt;p&gt;Now that we know what backend development is, we can say that a Backend Developer is responsible for managing all activities that occurs on a web server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Roles of a Backend Developer
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Writing server-side logic with a programming language of choice&lt;/li&gt;
&lt;li&gt;Processing data from user requests and performing actions on them&lt;/li&gt;
&lt;li&gt;Ensuring data is only accessible to users that are supposed to have access to it&lt;/li&gt;
&lt;li&gt;Fixing website bugs and errors&lt;/li&gt;
&lt;li&gt;Creating and managing databases&lt;/li&gt;
&lt;li&gt;Collaborating with the frontend to provide seamless communication between the frontend and backend&lt;/li&gt;
&lt;li&gt;Developing and integrating APIs to connect with other backend applications and services&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Before we dive head first into Backend Development, there are a few concepts and underlying architecture we need to understand, most of which forms an integral part of whatever we are going to be discussing and doing in the future.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisite Knowledge
&lt;/h3&gt;

&lt;p&gt;Having a basic knowledge of the underlying technology isn’t a waste of time. This usually proves useful in the long run and some of them include but are not limited to the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Internet&lt;/strong&gt;: How it works, what HTTP is, how browsers work, hosting etc.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Database&lt;/strong&gt;: Types (relational vs non-relational) and their use cases.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Servers&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Frontend&lt;/strong&gt;: Have a basic knowledge of front-end technologies and languages like HTML, CSS and JavaScript. Trust me on this, understanding how your data will be displayed to and submitted by the user will help you when formatting input and output. It also helps in understanding the structure of the frontend and how to effectively interact with it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Pick a Backend Language
&lt;/h3&gt;

&lt;p&gt;Picking a language to start with is another daunting task but I will suggest starting with one and learning its perks as well as its limitation. &lt;/p&gt;

&lt;p&gt;One good thing about learning a language is that when you decide the current one isn’t cutting it for you, learning another one won’t be hard as the knowledge of programming concepts such as loops, functions, variables etc. of one language is transferrable to other languages with a differences in its syntax and structure. &lt;/p&gt;

&lt;p&gt;There are a few programming languages which are suitable for writing backend code but I will only be listing the commonly used ones in no particular order. These include but are not limited to the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NodeJS (JavaScript for writing server side)&lt;/li&gt;
&lt;li&gt;PHP&lt;/li&gt;
&lt;li&gt;Python&lt;/li&gt;
&lt;li&gt;Ruby&lt;/li&gt;
&lt;li&gt;Java&lt;/li&gt;
&lt;li&gt;Golang and so on&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Amongst the above list, I started with and still use PHP as it runs on various platforms (Linux, windows etc.) and its compatible with almost all web servers used today (Apache, IIS).&lt;br&gt;
Its free to use and also easy to learn while supporting a wide range of relational databases such as MySQL which is another popular and widely used database.&lt;/p&gt;

&lt;p&gt;After picking a language, learn basic concepts like variables, loops, functions, arrays, if-else and switch statements and then ones you have a grasp of these, take it a step further by learning OOP – Object Oriented Programming if the language supports. This is not a must yet, but you’ll eventually need to learn that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pick a Database Management Systems
&lt;/h3&gt;

&lt;p&gt;You have learned how to write code with your preferred language but you feel like something is missing. All the codes you have been writing up till this point probably won’t have persistent data, that is, the user inputs are stored temporarily. This is where a database comes in. It helps retain such data and provides them again on request for reading and modification.&lt;/p&gt;

&lt;p&gt;A Database Management System (DBMS) is kind of like the software used in managing the database itself. This could further be classified based on the database model they support which can be &lt;strong&gt;Relational databases&lt;/strong&gt; (usually made up of a series of tables that contains rows and columns and they use a Structured Query Language (SQL) for interacting with the data) and &lt;strong&gt;Non-relational databases&lt;/strong&gt; (also referred to as NoSQL, doesn’t use the tabular form of storage used by relational databases).&lt;/p&gt;

&lt;p&gt;For starters, go with a relational database and my preferred choice would be MySQL as it pairs nicely with my preferred language which is PHP.&lt;/p&gt;

&lt;p&gt;It is not a must for you to go with these choices, your choice of backend language and database may differ from mine, just do a bit more research and find a pair that works for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn basic CRUD operations
&lt;/h3&gt;

&lt;p&gt;You must be wondering what CRUD means by now, don’t worry its nothing technical. Its just an acronym for the basic operations that occurs in the backend which are &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;C&lt;/strong&gt;reate: receive data from frontend and save to the database,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;R&lt;/strong&gt;ead: fetch data from the database and output to the frontend,&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;U&lt;/strong&gt;pdate: edit and update data stored in the database, and&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;D&lt;/strong&gt;elete: delete data stored in the database.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are few tutorials online (videos and articles) detailing how to go about this in your language and database of choice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn authentication and authorization
&lt;/h3&gt;

&lt;p&gt;After getting comfortable with CRUD operations, how about we put some privacy into it. Up until this point, any user has access to all parts of your web application. In order to prevent this and allow only certain users to have access to certain parts, information and actions on your web application, we need to add authorization logic to your web application.&lt;/p&gt;

&lt;p&gt;This involves creating login and signup code (authentication) which only allows users to have access to other parts of your application asides the login and signup screen and then based on the type of users (whether standard or administrator) you restrict access to some other parts further inside you application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Start building projects
&lt;/h3&gt;

&lt;p&gt;If you’ve managed to persevere and get this far in your learning path, I can confidently say that you’re on your way to becoming a world-class backend developer. Since you can confidently write code to create, read, update and delete data from a database, add authentication and authorization to your application, I think you can build the next Facebook now. &lt;/p&gt;

&lt;p&gt;I am only kidding though, but with these you can start with projects from as little as a Todo List (every beginner’s favorite) and then tune it up a bit by adding authentication and authorization in order to allow only the owners to view their own lists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learn a framework
&lt;/h3&gt;

&lt;p&gt;You have been working on a few projects now and have begun to notice some repeating patterns, a typical example being writing login and signup logic, authorization, writing logic to save and retrieve data from the database and they are beginning to get tedious.&lt;/p&gt;

&lt;p&gt;Some of you might have even found libraries and packages online, others may have a reusable and customizable template they created to help with them with these tasks, anyways, you are all trying to make your work easier and focus more on what matters right, and that’s where this wonderful thing called &lt;strong&gt;FRAMEWORKS&lt;/strong&gt; come in.&lt;/p&gt;

&lt;p&gt;A framework is a programming tool or set of reusable codes that come with pre-written components or solutions that can be customized in order to speed up development. Using framework can save you huge amount of time that would have been spent building things from the ground up and because of this, reduces the chances of errors. &lt;/p&gt;

&lt;p&gt;Other reasons to use frameworks are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reduce code duplication,&lt;/li&gt;
&lt;li&gt;simpler testing and debugging,&lt;/li&gt;
&lt;li&gt;you can focus on writing code that is specific to your project (more like business logic),&lt;/li&gt;
&lt;li&gt;easily reusable,&lt;/li&gt;
&lt;li&gt;comes preinstalled with industry-standard conventions and security measures etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Frameworks are usually built on top of existing programming languages some of which include but are not limited to the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;PHP – Laravel, Symfony, CodeIgniter, Yii, CakePHP etc.&lt;/li&gt;
&lt;li&gt;Python – Django, Flask etc.&lt;/li&gt;
&lt;li&gt;NodeJS (JavaScript) – Express.js, Meteor.js etc.&lt;/li&gt;
&lt;li&gt;Ruby – Ruby on Rails, Sinatra, Camping etc.&lt;/li&gt;
&lt;li&gt;Java – Spring etc.&lt;/li&gt;
&lt;li&gt;Golang – Fiber etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final notes
&lt;/h2&gt;

&lt;p&gt;One simple strategy that has always helped people to grow in this field is to learn by doing. Don’t get caught up watching tutorials, reading blog posts and never actually taking your time to practice all you have learned, take time after learning to apply this by building projects. Most people make a mistake of learning a lot of theory without actually applying it.&lt;/p&gt;

&lt;p&gt;It doesn’t matter if you picked up some dude’s code from the internet, take your time, read it, yes, I know what I said, read the code. Understand the purpose and what every function is trying to achieve then try recreating it by building your own. &lt;/p&gt;

&lt;p&gt;You need not create an exact copy of the project but provided you understood what it was trying to achieve and the process that was taken to achieve then you’re good.&lt;/p&gt;

&lt;p&gt;Take your time, understand concepts and keep on improving on your skills. Join communities and reach out whenever you are having issues and let google be your best friend. Even senior developers still search for a few things once in a while 😊. &lt;/p&gt;

&lt;p&gt;There is still a lot more topics to discuss and expand on, but that's not the purpose of this post. Its only but a guide as you will discover other topic and concepts I didn't talk about here. &lt;/p&gt;

&lt;p&gt;Have fun learning 👋. See you around.&lt;/p&gt;

</description>
      <category>backend</category>
      <category>backenddevelopment</category>
      <category>beginners</category>
      <category>guide</category>
    </item>
    <item>
      <title>Simple HTML form validation with PHP (a step-by-step guide)</title>
      <dc:creator>Abdulbaki Suraj</dc:creator>
      <pubDate>Wed, 28 Feb 2024 11:35:34 +0000</pubDate>
      <link>https://dev.to/codelikesuraj/simple-html-form-validation-with-php-a-step-by-step-guide-5b79</link>
      <guid>https://dev.to/codelikesuraj/simple-html-form-validation-with-php-a-step-by-step-guide-5b79</guid>
      <description>&lt;p&gt;In this tutorial, I'll be showing you how to perform a simple HTML form processing/validation using PHP. For the tutorial, we will build a simple user form that request for their full name and displays a welcome text after the user has entered their details in the html form and submitted.&lt;/p&gt;

&lt;p&gt;Let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  1) Setting up your environment
&lt;/h2&gt;

&lt;p&gt;If you already have your test environment ready, you can skip this step and jump to creating the file.&lt;/p&gt;

&lt;p&gt;For us to be able to properly view and test our application, we need to have some tools in place:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A browser (I will be using [Google Chrome Browser](&lt;a href="https://www.google.com/chrome)):" rel="noopener noreferrer"&gt;https://www.google.com/chrome)):&lt;/a&gt; Any browser will do.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A text editor (I am using [Sublime Text 3](&lt;a href="https://www.sublimetext.com/3)):" rel="noopener noreferrer"&gt;https://www.sublimetext.com/3)):&lt;/a&gt; This is to create, edit and save our code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A local web server installed (I use [XAMPP](&lt;a href="https://www.apachefriends.org/download.html" rel="noopener noreferrer"&gt;https://www.apachefriends.org/download.html&lt;/a&gt;) on windows 10): To simulate an http-server on your computer.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In case you run into some trouble setting up XAMPP, you can check out this &lt;a href="https://www.ionos.com/digitalguide/server/tools/xampp-tutorial-create-your-own-local-test-server" rel="noopener noreferrer"&gt;tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After all that is done, the next thing for you to do is to go into the "htdocs folder inside your XAMPP installation directory (mine is - C:\xampp\htdocs) and create a new folder (I'll name mine "form"). You can name it anything you want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720320672%2FjM8PQYd0S.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720320672%2FjM8PQYd0S.png" alt="creating a folder.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, open Sublime Text 3 and create a new file (ctrl + n).&lt;/p&gt;

&lt;p&gt;Copy and paste the following code into it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;
&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="s2"&gt;"Hello world!"&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720338709%2F69upRRJKe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720338709%2F69upRRJKe.png" alt="pasting code.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then save it as index.php inside the folder you created.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720358728%2FD8YbXvI-y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720358728%2FD8YbXvI-y.png" alt="saving code.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next step after ensuring the XAMPP server is running is to go to your browser and type this into the URL bar &lt;code&gt;http://localhost/name_of_your_folder&lt;/code&gt;. Your browser screen should look something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720373554%2FlQYvy8qEV.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720373554%2FlQYvy8qEV.png" alt="showing the hello.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If all goes well, you can proceed to the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  2) Writing the HTML for the form
&lt;/h2&gt;

&lt;p&gt;In your &lt;code&gt;index.php&lt;/code&gt; file, clear any previous code there and copy and paste the following into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
/*php main code goes here*/
?&amp;gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;My Form&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h2&amp;gt;My form&amp;lt;/h2&amp;gt;
    &amp;lt;form method="post"&amp;gt;
        &amp;lt;?php 
        /* php error and display code goes here */
        ?&amp;gt;
        Name: 
        &amp;lt;input type="text" name="username"&amp;gt;&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;
        &amp;lt;input type="submit" name="submit_form" value="SUBMIT"&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is just a simple html form with an input field and a submit button. After this is added, save (ctrl + s) again on the text editor and reload the page on the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720394198%2F60fGu8VRi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720394198%2F60fGu8VRi.png" alt="showing the form.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cool, now we have our form, but typing stuffs into the box and clicking the submit button won't do anything.&lt;/p&gt;

&lt;p&gt;Alright, let's move on to the real deal and probably what brought you here in the first place - creating a few lines of PHP 🐘 code.&lt;/p&gt;

&lt;h2&gt;
  
  
  3) Writing the PHP test cases
&lt;/h2&gt;

&lt;p&gt;Note that in the HTML form earlier, our method attribute was "post" &lt;code&gt;&amp;lt;form method="post"&amp;gt;&lt;/code&gt;, this is how the data entered by the user is transferred to the server and we shall be making using of &lt;code&gt;$_POST['name_in_form']&lt;/code&gt; function to retrieve our data. Here are some of the conditions we are going to be checking for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check if the user submitted an empty field - this will be checked using the [empty(str) function](&lt;a href="https://www.w3schools.com/php/func%5C_var%5C_empty.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/php/func\_var\_empty.asp&lt;/a&gt;),&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if the user submitted a numeric value - this will be checked using the [is_numeric(str) function](&lt;a href="https://www.w3schools.com/php/func%5C_var%5C_is%5C_numeric.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/php/func\_var\_is\_numeric.asp&lt;/a&gt;),&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check if the number of words submitted is less than 2 so as to ensure the user submits at least a first and a last name - this will be checked using the [str_word_count(str) function](&lt;a href="https://www.w3schools.com/php/func%5C_string%5C_str%5C_word%5C_count.asp" rel="noopener noreferrer"&gt;https://www.w3schools.com/php/func\_string\_str\_word\_count.asp&lt;/a&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Copy and paste the following code just below the line where you have &lt;code&gt;/* php main code goes here */&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'submit_form'&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//create a variable to store the display message&lt;/span&gt;
    &lt;span class="nv"&gt;$display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      

    &lt;span class="c1"&gt;//assign the value of $_POST['username'] to $full_name variable&lt;/span&gt;
    &lt;span class="nv"&gt;$full_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_POST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'username'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;//check if there is no data in the variable&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;empty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$full_name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Error: Input is empty, please enter a name !"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;//check if the data is a number&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;is_numeric&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$full_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Error: Name cannot be numeric"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;//check if the number of words is not less than two&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;str_word_count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$full_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Error: Please enter a valid first and last name"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;//if all the above conditions are false&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$display&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hey "&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;htmlentities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$full_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="s2"&gt;", you are awesome :)"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I added a lot of commenting in the code in other to make it self-explanatory.&lt;/p&gt;

&lt;p&gt;And also copy the following code just below the line where you have &lt;code&gt;/* php error and display code goes here */&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;//display the variable if a value has been set&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$display&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$display&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code allows us to visually see the errors they encounter during the validation process.&lt;/p&gt;

&lt;p&gt;To avoid PHP errors from disrupting the screen, the &lt;code&gt;isset($display)&lt;/code&gt; condition is used to ensure the variable is set (that is, a value has been passed into it) before there is any reason to display anything.&lt;/p&gt;

&lt;p&gt;Below are screenshots of the application displaying the errors.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720433343%2FLY1F667pB.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720433343%2FLY1F667pB.png" alt="first error.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720448845%2F1vxu505dz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720448845%2F1vxu505dz.png" alt="second error.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720480327%2FKXjZDfa85.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720480327%2FKXjZDfa85.png" alt="third error.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here's a bonus 😉 screenshot of me entering correct values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720498468%2FVfUNpF_pW.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1600720498468%2FVfUNpF_pW.png" alt="my success.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for following me till the end of the tutorial and I hope you have learned something new too.&lt;/p&gt;

</description>
      <category>php</category>
      <category>html</category>
      <category>form</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
