0%
Loading ...

Parvesh Sandila

Parvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master's degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​

HTML List

In this tutorial, we will learn about HTML List. HTML list is normally used to show ordered or un-ordered list in HTML. For example, you want to show a list of available food items on a restaurant website. In this case, you can use HTML List. We have a total of three types of lists available in HTML. Ordered List UnOrdered List Description List Ordered List : In Ordered list, all the list items will be marked with numbers by default. Ordered lists start and ends with Ol tag and we write all the list items in li tag. Check this example. <ol> <li>Pizza</li> <li>Burger</li> <li>Sandwich</li> </ol> Output: Pizza Burger Sandwich Unordered List : In UnOrdered list, all the list items will be marked with dots by default. UnOrdered starts and ends with ul tag and we write all the list items in li tag. Check this example. <ul> <li>Pizza</li> <li>Burger</li> <li>Sandwich</li> </ul> Output: Pizza Burger Sandwich Description List : Description list starts with dl tag and after that, we use two tags dt and dd tags to add description title and description data respectively. <dl> <dt>Pizza</dt> <dd>250 Rs</dd> <dt>Burger</dt> <dd>110 Rs</dd> <dt>Sandwich</dt> <dd>100 Rs</dd> </dl> Output: Pizza 250 Rs Burger 110 Rs Sandwich 100 Rs Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

HTML List Read More »

HTML Images

In this tutorial, we will learn about HTML Images. We use an image tag to add images on the web page. To add an image in the web page we have to add an img tag and an src attribute in the img tag. In src attribute, we add the path of the image. This image path may be internal or external. Means image may be present on the same website or from some other website. Let’s check how to add image tag in HTML code. Here is code which shows how you can add an image(internal image) on the web page if the image and web page both are saved at one server( in single folder e.g Desktop of your PC) Internal Source Example: – <img src=”flower.png” height=”300px” width=”300px” alt=”flower image”/> External Source Example: – Here we will check how we can add the image from an external source. <img src=”https://images-na.ssl-images-amazon.com/images/I/71K8SKRk4gL._SX425_.jpg” height=”300px” width=”300px” alt=”flower image”/> Output: – Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

HTML Images Read More »

Include and Require in PHP

In this tutorial, we will learn about include and require in PHP. Include and Required both are used to copy text/code/markup from the specified file into the file where the copy or require statement is used. Include and require in PHP makes it so simple to manage such kind of code which we need in multiple files for example code for the navigation bar and footer(because we need same navigation bar and footer in multiple pages). Before diving deep it is important to know what is different between these two statements(include and require) Difference between include and require: We know both include and require are used to copy content from one file into another but they both works differently only in the case upon failure(file not found): require will show a fatal error (E_COMPILE_ERROR) and stop the script from executing include will only show a warning (E_WARNING) and the script will continue to execute Syntax of require and include: include ‘filename’; or require ‘filename’; PHP include example program: First of all, we will create a file which we want to include. Suppose we have saved this file as hello.php. <?php echo “<h2>Hello, Welcome to Owlbuddy.</h2>”; ?> Now we will write the code of another file where we want to include hello.php. <html> <body> <?php include ‘hello.php’;?> </body> </html>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Include and Require in PHP Read More »

PHP Global Variables

In this tutorial, we will learn about PHP Global Variables. The global variables are also known as superglobals and These these superglobal variables first time introduced in PHP 4.1.0 on 10 December 2001. A very interesting thing about these superglobal variables is these variables are always accessible. You can access them in different PHP files easily. Please check out the following list of superglobals: $GLOBALS $_SERVER $_REQUEST $_POST $_GET $_FILES $_ENV $_COOKIE $_SESSION $GLOBALS: The $GLOBALS global variable is used to access global variables from anywhere(functions, methods) in the script. In PHP all the global variables in an array which is known as $GLOBALS[index]. In the index, we write the name of the variable to fetch or to add value in the variable. To understand it wisely, please checks out the following example program. <?php $num1 = 40; $num2 = 30; function sum() { $GLOBALS[‘ans’] = $GLOBALS[‘num1’] + $GLOBALS[‘num2’]; } sum(); echo $ans; ?> $_SERVER The $_SERVER global variable holds the information about the about headers, paths, and script locations. List of important $_SERVER elements: Element Description $_SERVER[‘PHP_SELF’] This returns the name of the currently executing script file. $_SERVER[‘GATEWAY_INTERFACE’] This returns the version of the Common Gateway Interface (CGI) the server is using. $_SERVER[‘SERVER_ADDR’] This returns the IP address of the host server. $_SERVER[‘SERVER_NAME’] This returns the name of the host server (For example www.owlbudy.com). $_SERVER[‘SERVER_SOFTWARE’] This returns the server identification string (For example Apache/2.2.24). $_SERVER[‘SERVER_PROTOCOL’] This returns the name and revision of the information protocol (For example HTTP/1.1). $_SERVER[‘REQUEST_METHOD’] This returns the request method which is used to access the page (For example POST). $_SERVER[‘REQUEST_TIME’] This returns the timestamp of the start of the request (For example 1245124512). $_SERVER[‘QUERY_STRING’] This returns the query string in case the page is accessed using a query string. $_SERVER[‘HTTP_ACCEPT’] This returns the accept header from the current request. $_SERVER[‘HTTP_ACCEPT_CHARSET’] This returns the Accept_Charset header from the current request. $_SERVER[‘HTTP_HOST’] This returns the header of host from current request. $_SERVER[‘HTTP_REFERER’] This returns the complete URL of current page. $_SERVER[‘HTTPS’] This is the script queried via a secure HTTPS protocol. $_SERVER[‘REMOTE_ADDR’] This returns the IP address of users machine from which user is communicating. $_SERVER[‘REMOTE_HOST’] This returns name of host on user’s machine. $_SERVER[‘REMOTE_PORT’] This returns port number of users machine which is using for web communication. $_SERVER[‘SCRIPT_FILENAME’] This returns absolute path name of currently executing script. $_SERVER[‘SERVER_ADMIN’] This returns the information about the server admin. $_SERVER[‘SERVER_PORT’] This returns the port number which a machine using for web communication. $_SERVER[‘SERVER_SIGNATURE’] This return version of server and name of the host. $_SERVER[‘PATH_TRANSLATED’] This return path to script according of file path system. $_SERVER[‘SCRIPT_NAME’] This returns the path of current script. $_SERVER[‘SCRIPT_URI’] This returns the URI of current page. Example Program: <?php echo $_SERVER[‘PHP_SELF’]; echo “<br>”; echo $_SERVER[‘HTTP_REFERER’]; echo “<br>”; echo $_SERVER[‘HTTP_HOST’]; echo “<br>”; echo $_SERVER[‘SERVER_NAME’]; echo “<br>”; echo $_SERVER[‘SCRIPT_NAME’]; ?> $_REQUEST The $_REQUEST global variable is used to collect data from form. <?php if ($_SERVER[“REQUEST_METHOD”] == “POST”) { // collect value of input field $name = $_REQUEST[‘name’]; if (empty($name)) { echo “It’s empty.”; } else { echo $name; } } ?> <form method=”post” action=”<?php echo $_SERVER[‘PHP_SELF’];?>”> Name: <input type=”text” name=”name”> <input type=”submit”> </form> $_POST The $_GET global variable is used to collect data from the form in case data is submitted using the POST method. To understand it wisely please check out the following example program. <?php if(isset($_POST[“Submit”])){ echo “<p–>Hello, ” . $_POST[“name”] . “<p></p>”; } ?> <form method=”POST”> <input type=”text” name=”name”> <input=”” value=”Submit”> </form> $_GET The $_GET global variable is used to collect data from the form in case data is submitted using the GET method. To understand it wisely please check out the following example program. <?php if(isset($_GET[“Submit”])){ echo “<p–>Hello, ” . $_GET[“name”] . “<p></p>”; } ?> <form method=”GET”> <input type=”text” name=”name”> <input=”” value=”Submit”> </form> $_FILES The $_FILES is a two-dimensional associative global array of items which are being uploaded by via HTTP POST method. $_ENV The $_ENV is used to return the environment variables from the web server. $_COOKIE The $_COOKIE global variable is used to store some data on client’s machines in the form of a text file. The main motive of storing cookies on the client machine is to identify the user when user will revisit a site.  <?php $cookie_name = “user_name”; $cookie_value = “Rahul”; setcookie($cookie_name, $cookie_value); ?> Click here to learn about $_COOKIE global variable in detail. $_SESSION The $_SESSION is global variable which is used to store information and to be used across multiple pages. To understand it wisely please check out the following example program. <?php // Starting the session session_start(); // Setting session variables and values $_SESSION[“login_status”] = “true”; $_SESSION[“username”] = “Abc”; ?> Click here to learn about $_SESSION global variable in detail. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

PHP Global Variables Read More »

PHP Cookies

In this tutorial, we will learn about PHP Cookies. PHP Cookies are used to store some data on client’s machines in the form of a text file. The main motive of storing cookies on the client machine is to identify the user when user will revisit a site. Because whenever a user requests a web page to the server it also sends cookies to the server. To understand it you can check the following illustration. As in the above illustration, you can see the first time the user is just sending a normal request to the server. But the server is giving back response and cookies to the client and after this when the client again try to send a request to the server it is sending cookies back to the server with the request. Creating PHP cookies: We have setcookie() function available in PHP to create a cookie. For example, you want to save a cookie to store the name of the user. Syntax of setcookies(): setcookie(cookie_name, cookie_value, expire_time, path, domain, secure, httponly); In the above syntax except for cookie_name, all the other parameters are optional. Please check out the following example program. Example Program: <?php $cookie_name = “user_name”; $cookie_value = “Rahul”; setcookie($cookie_name, $cookie_value); ?> Fetching Cookies variables: After storing PHP cookies on the client’s machine we will get all the cookies variable and values when user will revisit the site. Here is an example program to show how we can fetch these cookies variables using $_COOKIE global variable. Example Program: <?php $cookie_name = “user_name”; $cookie_value = “Rahul”; setcookie($cookie_name, $cookie_value); if(isset($_COOKIE[$cookie_name])) { echo “Hello “. $_COOKIE[$cookie_name]; } ?> Updating the value of the cookie variable: We can update the value of cookie variable any number of time using setcookie() function. Example Program: <?php $cookie_name = “user_name”; $cookie_value = “Rahul”; setcookie($cookie_name, $cookie_value); ?> Deleting cookie variables: To delete the cookie we can use setcookie() function with an expiration date in the past. Example Program: <?php $cookie_name = “user_name”; $cookie_value = “Rahul”; setcookie($cookie_name, $cookie_value,time() – 3600); ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

PHP Cookies Read More »

PHP Sessions

In this tutorial, we will learn about PHP Sessions. PHP sessions are a way to access data among different web pages of the website. All the session variables and their values stored in a file in the temporary directory on the server. With the help of PHP sessions, we can share various kind of data among all the pages of the website such as login_status, username etc. It is important to note that By default, session variables last until the user closes the browser. How to start PHP Sessions: We have session_start() function in PHP to start a session in PHP and to create and set a session variable in PHP we use $_SESSION global variable. Please check out the following example program: Example Program: <?php // Starting the session session_start(); // Setting session variables and values $_SESSION[“login_status”] = “true”; $_SESSION[“username”] = “Abc”; ?> Get PHP Session variables: After starting a session and creating session variables we can fetch session variables in different web pages of the website. Please check out the following example program. Example Program: <?php // Starting the session session_start(); // Setting session variables and values $_SESSION[“login_status”] = “true”; $_SESSION[“username”] = “Abc”; echo “Hello ” . $_SESSION[“username”]; ?> Modifying session variables: We can modify session variables any number of times. For example, you want to changes login_status to false after user clicks on the logout button. Please check out the following example program. Example Program: <?php // Starting the session session_start(); // Setting session variables and values $_SESSION[“login_status”] = “true”; $_SESSION[“username”] = “Abc”; echo “Hello ” . $_SESSION[“username”]; //modifying session variable $_SESSION[“username”] = “XYZ”; echo “Hello ” . $_SESSION[“username”]; ?> As in above example program you can see in the beginning(on 6th line) of the program the value of variable username was Abc but later(on 10th line) we changed this the value of username variable to XYZ. So it means to change the value of session variable you just have to assign a new value to a variable and that’s it. Removing session variables: There are two functions in PHP to remove session variables. First one is session_unset() to remove all the session variables and the second one is session_destroy() is to destroy the complete session. Please check out the following example program to understand this more wisely. Example Program: <?php // Starting the session session_start(); // Setting session variables and values $_SESSION[“login_status”] = “true”; $_SESSION[“username”] = “Abc”; echo “Hello ” . $_SESSION[“username”]; // remove all the session variables session_unset(); // destroy the complete session session_destroy(); ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

PHP Sessions Read More »

PHP File Handling

In this tutorial, we will learn about PHP File Handling. File Handling is really useful if you want to perform some any file-related operations in your web application such as creating a new file, opening an existing file, delete a file etc. Here is a list of file-related operations: Creating a new file Opening an existing file Reading from file Writing in the file Closing a file Deleting a file Creating a new File: Many times we need to create a new file in our web application. We use fopen() function to create a new file in PHP File Handling. The fopen() function works in a very simple manner if a file already exists it will open that otherwise, it will create a new file. It is important to note if you want to create a new file then the file must file is opened for writing (w) or appending (a). Example Program: <?php $newfile = fopen(“NewFile.txt”, “w”) or die(“Couldn’t open this file”); fclose($newfile); ?> Opening an existing file: As we learned in the last example we use fopen() function to open a file. You can open a file to read to write or to append also. Please check out the following example. Example Program: <?php $myfile = fopen(“myFile.txt”, “r”) or die(“Couldn’t open this file”); fclose($myfile); ?> Modes in which we can open a file: Mode Description w This mode is used to open a file just for writing in the file. If the file already not exist it will create a new file and if file exists it will remove all the existing data from the file. r This mode is used to open a file just for reading from the file. a This mode is used to open a file just for writing in the file. If the file already not exist it will create a new file and if file exists it will preserve all the existing data from the file and the file pointer will point out the end of the file. w+ This mode is used to open a file for writing and reading the file. If the file already not exist it will create a new file and if file exists it will remove all the existing data from the file. r+ This mode is used to open a file for reading and write the file a+ This mode is used to open a file just for writing and reading the file. If the file already not exist it will create a new file and if file exists it will preserve all the existing data from the file and the file pointer will point out the end of the file. x This mode is used to create a new file to write only. Reading from file: We have fread() function in PHP to read a file. This fread() function can take two parameters first one is the name of the files and the second one is the number of bytes to read from the file. Example Program: <?php $myfile = “c:\\myfile.txt”; $reading = fopen($myfile, “r”); $text = fread($reading, filesize($myfile)); echo $text; fclose($handle); ?> Writing in the file: We have fwrite() function. We can create a new file using this function and write or append in the file. This fwrite() function takes to parameters first one is the filename and the second one is content which you want to write in the file. <?php $myfile = fopen(“myfile.txt”, ‘w’); $content = “Hello, Welcome to Owlbuddy.\n”; fwrite($myfile, $content); ?> Closing a file: We have fclose() function in PHP to close opened file. This fclose() function takes an only a single parameter which is the file name. <?php $myfile = fopen(“myfile.txt”, ‘w’); $content = “Hello, Welcome to Owlbuddy.\n”; fwrite($myfile, $content); fclose($myfile); ?> Deleting a file: We have the unlink() function in PHP. To delete an existing file. This function takes only a single parameter which is the file name. <?php unlink(‘myfile.txt’); ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

PHP File Handling Read More »

PHP Form Handling

In PHP GET and POST superglobals are used to collect form-data. In our first example program, we will create a search web page using the get method. let’s start with the search page example. Example Program: <?php if(isset($_GET[“submit”])){ echo “<h2>Your are searching for ” . $_GET[“search”] . “</h2>”; } ?> <html> <body> <form method=”GET”> <input type=”text” name=”search” placeholder=”Search Product Here”><br> <input type=”Submit” name=”submit”> </form> </body> </html> As you can see in the above example how we create a search page using the GET method. (In this tutorial we are not using any database but don’t worry in MYSQL tutorials we will also perform search operations in the database using PHP)  In our next example program, we will create a login form using the POST method. Please keep in your mind we always use the POST method for login, and signup pages because we don’t want to show user data in the URL bar. (Here we will use a static username and password value but in the MySQL tutorial, we will perform the login by searching the user from the database) Example Program: – <?php $valid_email=”admin@xyz.com”; $valid_password=”123″; if(isset($_POST[“submit”])){ $email=$_POST[“email”]; $password=$_POST[“pass”]; if($valid_email==$email&&$valid_password==$password){ echo “<h2>Welcome, your are a valid user</h2>”; } else{ echo “<h2>Please check your email and password</h2>”; } } ?> <html> <body> <form method=”POST”> <input type=”text” name=”email” placeholder=”Please Enter Your Email”><br> <input type=”password” name=”pass” placeholder=”Please Enter Your Password”><br> <input type=”submit” name=”submit”> </form> </body> </html> As we created this login page in the same way you can create a signup page using the POST method. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

PHP Form Handling Read More »

Comments in PHP

Comments are not used to perform any function in the program but are useful for developers. Developers can write comments with variables and functions to remember their working (purpose) in the program. One important thing to mention is that comments don’t have any impact on the execution of the program. Types of Comments: Single Line comments Multi-Line comments Single-Line Comments: – These are used to add single-line comments with a variable or any function. There are two ways to write single-line comments using the // symbol or # symbol. Example Program: – <?php // Single comment using // symbol # Single comment using # symbol echo “Welcome to Owlbuddy”; ?> Multi-Line Comments: – These are used to add a multi-line comment with a variable or any function. /* */ symbols are used to add Multi-Line comments. Example Program: – <?php /* These multiline comments also use to hide code. */ echo “Welcome to Owlbuddy”; ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Comments in PHP Read More »

GET and POST in PHP

The web browser communicates with the web server by using two HTTP methods GET and POST. These methods are used to send information to the web server. Here we will learn about these methods and the difference between these two methods. GET method: When we use the GET method it sends data to the web server as URL parameters. It sends data to a web server in the key-value pair. When you work with the GET method you can easily see all GET parameters in the URL bar like this http://www.example.com/search.php?product=books. Here we will learn how we can send data from an HTML form to a server using the GET method. Example Program: <?php if(isset($_GET[“Submit”])){ echo “<p–>Hello, ” . $_GET[“name”] . “<p></p>”; } ?> <form method=”GET”> <input type=”text” name=”name”> <input=”” value=”Submit”> </form> POST method: When we send data using the POST method to the webserver. Data would not visible in the URL bar. In the POST method data send to the web server separately as a package with a processing script. Check this example to understand it. Example Program: <?php if(isset($_POST[“Submit”])){ echo “<p–>Hello, ” . $_POST[“name”] . “<p></p>”; } ?> <form method=”POST”> <input type=”text” name=”name”> <input=”” value=”Submit”> </form>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

GET and POST in PHP Read More »

Scroll to Top
×