Transaction: c6d157b2032f852ea0966190ac4a9265f0423124

Included in block 89,119,588 at 2024/10/02 05:21:39 (UTC).

Transaction overview

Loading...
Transaction info
transaction_id c6d157b2032f852ea0966190ac4a9265f0423124
ref_block_num 56,145
block_num89,119,588
ref_block_prefix 3,113,984,900
expiration2024/10/02T05:31:30
transaction_num 3
extensions[]
signatures 200fcd825eef4f7d1a63d2be3d82de4060953ca3817aa8803f387b65b35fba48cb6ceca7e91e2280832fe27d0ef3239bcda50b669c99a25f4cdeb91f138d489724
operations
comment
"parent_author":"",<br>"parent_permlink":"dynamicdevs-s20w4",<br>"author":"hudamalik20",<br>"permlink":"sec-s20w4-or-introduction-to-php-part-2",<br>"title":"SEC S20W4 | Introduction to PHP Part - 2",<br>"body":"<div class= \"text-justify\">\n\n|<center>Hello Everyone ! <\/center>|\n| - |\n\n I am @hudamalik20 from Pakistan. I hope you all are doing well and having a great time. Today,<br> I am excited to take part in **SEC S20W4 | Introduction to PHP Part - 2**,<br> organized by @starrchris ,<br>So let's start.\n\n\n![Blue Geometric Business YouTube Thumbnail_20241002_101818_0000.png (https:\/\/cdn.steemitimages.com\/DQmR6c667d4BzWb3ETR8UJoTYSfFbeLhFcAsrqpZBaEmbvb\/Blue%20Geometric%20Business%20YouTube%20Thumbnail_20241002_101818_0000.png)\n\n\n<center><sup>Designed by me ,<br> edited on Canva<\/sup><\/center>\n\n\n\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n\n### Section 1: Theoretical Questions\n\n---\n\n1.**Explain in detail what exceptions are,<br> what they are used for,<br> and how they handle errors in PHP. Include an example of using the try and catch blocks.**\n\n---\n\n**Exceptions** in PHP are a way to handle unexpected errors that may occur during code execution. Instead of letting the program crash,<br> we use certain keywords like **try**,<br> **catch**,<br> **finally**,<br> and **throw** to manage the error gracefully. \n\n- **Try Block**: In PHP,<br> when we expect some error might occur,<br> we write that part of the code inside the **try block**.\n- **Catch Block**: The **catch block** is used to handle the error that occurs inside the try block. If an error (exception) happens,<br> the catch block is executed.\n\n- **Throw**: This keyword is used to create an exception manually. We can throw an error when something goes wrong and handle it in the catch block.\n\n\n\n![p1.PNG (https:\/\/cdn.steemitimages.com\/DQmUS1N7hxCJuiarpDiDxAj4o1XCBFPYJ4sRERKmj9oh9Qb\/p1.PNG)\n\n\n\nFor every **try block**,<br> there must be at least one **catch** or **finally** block. If an exception is not handled (no catch block),<br> PHP will generate a **fatal error** and stop the execution of the program.\n\nSo these are used to handle those parts of the code where an unexpected error might occur. We handle these errors using the try catch combination. The code inside the try block is executed,<br> and if an error occurs,<br> it is caught by the catch block,<br> which can show an error message or take another action.\n\n\n\n\n\n\nSo In this example:\n- I define a function `divide()` that checks if I am dividing by zero. If so,<br> it throws an exception.\n- The **try** block attempts to execute the `divide(10,<br> 0)` function. Since dividing by zero is not allowed,<br> an exception is thrown.\n- The **catch** block catches the exception and displays the error message \"Cannot divide by zero\".This way,<br> **exceptions** help me control the flow of the program even when errors occur.\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n---\n\n2.**What are six common types of PHP errors? Provide examples for each.**\n\n\n----\n\n**Parse Error:**\nA **Parse Error**,<br> also known as a **Syntax Error**,<br> occurs when there's a mistake in the code structure,<br> making it difficult for PHP to understand and execute. In this example,<br> I've missed a semicolon at the end of the `echo` statement:\n\n\n![p2.PNG (https:\/\/cdn.steemitimages.com\/DQmWJBLbLWP9rjH7kRtzwspRWi75fdxh8FzmSTULG4buHbT\/p2.PNG)\n\n\nPHP requires proper syntax,<br> like adding semicolons to separate statements. Because I forgot the semicolon here,<br> PHP will throw a **Parse Error** when the code runs. It will specifically point out where the issue is,<br> showing a message indicating that something is wrong at or near the line where the mistake happened. This helps in quickly identifying and fixing the error.\n\n\n---\n\n**Fatal Error:**\nA **Fatal Error** occurs in PHP when the script tries to perform an action that is not possible,<br> such as calling a function,<br> class,<br> or including a file that does not exist in the program. This kind of error typically happens due to misspelling the function name or forgetting to define the function before calling it. \n\nWhen a fatal error is encountered,<br> the PHP script stops executing,<br> and no further code is run. This can disrupt the entire functionality of the program,<br> and PHP throws the fatal error to notify the issue.\n\n\n![p3.PNG (https:\/\/cdn.steemitimages.com\/DQmZ4Lj5GAk2qUk8XDJL4KyxWPPW8dBnspSUN4xthShQJFG\/p3.PNG)\n\n\nIn this case,<br> the script is trying to call `nonExistentFunction()`,<br> which hasn't been defined anywhere in the program. PHP will immediately throw a fatal error and stop executing the rest of the code. The error message will indicate that the function does not exist,<br> and PHP won't proceed beyond this point until the error is resolved.\n\n\n---\n\n\n**Warning Error:**\nA **Warning Error** in PHP occurs when the script encounters a problem,<br> but it does not prevent the execution of the code. Unlike fatal errors,<br> a warning doesn't stop the script; it only shows a message indicating the issue while allowing the script to continue running. \n\nAlthough the program continues,<br> it's important to fix these warnings to avoid unexpected behavior in the long run. Warnings are non-fatal errors and are typically related to issues such as including files that don\u2019t exist or improper usage of functions.\n\n\n![p4.PNG (https:\/\/cdn.steemitimages.com\/DQmbmqw84XEFXkr28bSFj5weNmmUKDDT8vBy34a924muXU4\/p4.PNG)\n\n\nIn this case,<br> PHP will show a warning because it cannot find `non_existent_file.php`. However,<br> the script will continue to execute,<br> and you will see the message \"This will still execute even after the warning.\" despite the warning being displayed.\n\n\n---\n\n\n**Notice Error:**\nA **Notice Error** in PHP is a minor issue that occurs when something is not entirely right with the code,<br> but it doesn't stop the script from executing. This type of error commonly arises when trying to use an undefined variable,<br> meaning the variable hasn't been initialized before being used. \n\n\nWhile notice errors don't significantly impact the execution of the code but a good practice to fix them to avoid any unexpected behavior in the program.\n\n\n![p5.PNG (https:\/\/cdn.steemitimages.com\/DQmYmCxouSU8dyPZUKBNPZ8MLnZ8WgsEap8tE7nV6atuaHx\/p5.PNG)\n\n\nIn this case,<br> PHP will throw a notice error because `$undefinedVariable` was never defined or initialized. Despite the notice,<br> the script will continue to execute.\n\n---\n\n**Deprecated Error:**\nA **Deprecated Error** in PHP occurs when we use an outdated function or feature that is no longer recommended for use. As PHP evolves,<br> newer functions and features are introduced,<br> while older ones may become obsolete.\n\n When we use these deprecated functions,<br> PHP issues a warning,<br> advising us to update our code to use the latest alternatives.\n\n\n![p6.PNG (https:\/\/cdn.steemitimages.com\/DQmZjQMdaQeHBDP5ZJWqjQHAb52cJncusWGXzYSVT88H5uF\/p6.PNG)\n\n\nIn this code snippet,<br> we use the `split()` function,<br> which is deprecated. When we execute this code,<br> PHP generates a deprecated error,<br> signaling that this function should be replaced with a more current alternative,<br> such as `explode()`. This warning helps us ensure that our code remains compatible with future versions of PHP and allows us to take advantage of improved features.\n\n\n---\n\n\n**Undefined Index Error:**\nAn **Undefined Index Error** occurs when we try to access an index in an array that does not exist. This type of error is not very noticeable but commonly happens when working with arrays. An index refers to the position of an element within the array. \n\n\n![p7.PNG (https:\/\/cdn.steemitimages.com\/DQmaEHS55yQpM68ygyP2ktSS2y4KcMA7HuJGmX4zNgfKxgL\/p7.PNG)\n\n\nIn this example,<br> we have an array called `$fruits` that stores two elements: 'apple' at index 0 and 'orange' at index 1. However,<br> when we try to access `$fruits[2 `,<br> we encounter an Undefined Index Error because there is no third element in the array. We only have two indexes available: 0 and 1. This error indicates that we are trying to access an index that does not exist,<br> which can lead to unexpected results in our program.\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n----\n\n\n3.**Describe three personal experiences with errors in PHP coding.**\n\n----\n\n\n **Syntax Error (Parse Error)**\n\nOne of the most frequent errors I've encountered while coding in PHP is a syntax error,<br> also known as a parse error. This typically happens when there\u2019s a missing semicolon or a typo in the code,<br> which prevents the PHP interpreter from parsing the script correctly.\n\n\n\nFor instance,<br> once I forgot to add a semicolon at the end of an `echo` statement. Here\u2019s an example:\n\n\n\nIn this case,<br> PHP threw a **parse error**,<br> halting the execution of the script and pointing to the line where the mistake occurred. I quickly realized that missing a semicolon caused the issue,<br> added it back,<br> and the script ran fine.\n\n Now i always check for missing semicolons and typos in the code. Syntax errors are simple but can be frustrating.\n\n---\n\n **Fatal Error**\n\nAnother error I often encountered is a **fatal error**,<br> which occurs when I try to call a function that hasn\u2019t been defined or when a class does not exist. This error is more serious because PHP immediately stops execution when it occurs.\n\n\n![p3.PNG (https:\/\/cdn.steemitimages.com\/DQmZ4Lj5GAk2qUk8XDJL4KyxWPPW8dBnspSUN4xthShQJFG\/p3.PNG)\n\nIn this case,<br> PHP throws a fatal error,<br> telling me that the `nonExistentFunction()` is undefined. The program execution stops entirely,<br> which means the script won\u2019t run further until I either define the function or remove the call to it.\n\n\n Now I make sure to define all functions or include necessary files before calling them in the code. \n\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n---\n\n**Undefined Variable Error (Notice Error)**\nA **notice error** often occurs when I try to use a variable that hasn\u2019t been initialized yet. It doesn\u2019t stop the script from running,<br> but PHP will throw a warning message,<br> and the output might not be what I expect.\n\n\n\n\nIn this PHP will throw a **notice error**,<br> stating that `$undefinedVariable` is undefined. The script will still continue to run,<br> but this warning can help catch potential issues,<br> especially when working with variables that are supposed to hold important values.\n\nAlways initialize variables before using them in the code to avoid notice errors.\n\nEach of them has shown me the importance of writing clean and correct code,<br> handling variables properly,<br> and making sure all necessary components are defined before they are used.\n\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n----\n\n**4.\"Explain the include syntax in PHP and its benefits.\"**\n\n---\n\nThe `include` statement in PHP allows us to merge one PHP file into another. This means we can add specific files that we have created in our code to another PHP file,<br> which makes it easier to manage our code.\n\n\nWhen we build a website,<br> we often have common elements like headers,<br> footers,<br> menus,<br> and database connection scripts that we want to use on multiple pages. Instead of writing the same code for the header and footer on each page,<br> we can use the `include` statement to access these common files. \n\n\n\n\n\n**php\ninclude('header.php');**\n\n\n\n\n![p8.PNG (https:\/\/cdn.steemitimages.com\/DQmVS6FGWcj3KCr14eNpa2Er2irmNU6te9gKZWHVQkCp1mq\/p8.PNG)\n\n\n![p9.PNG (https:\/\/cdn.steemitimages.com\/DQmdqCNhEohLZm9bhgtMTVSUvgN5bpayFJsYGanLcy3MkGk\/p9.PNG)\n\n\n\n![p10.PNG (https:\/\/cdn.steemitimages.com\/DQmQr5FyS9b8hgXVxsLQeipSzF3xt2qoQTAZFFo16fGGggs\/p10.PNG)\n\n![p11.PNG (https:\/\/cdn.steemitimages.com\/DQmdsB3PvBiMrMKLVskLyhRAu8Zh7a4GoHd6uAKqEpLUVoX\/p11.PNG)\n\n\n\n**Benefits of Using `include`**\n\n1. **Code Reusability**: As I mentioned earlier,<br> we can reuse the same header and footer on multiple pages. This reduces the amount of code we have to write.\n\n2. **Easy Maintenance**: When we need to update the header or footer,<br> we only change it in one place. This saves us time because we don\u2019t have to update every single page. The changes will automatically reflect everywhere we used `include`.\n\n3. **Organized Code**: By using `include`,<br> we can divide our code into smaller parts. For example,<br> we can create separate files for the header,<br> footer,<br> and navigation menu. This makes our code easier to read and manage.\n\n4. **Reduced Duplication**: Since we are not copying and pasting the same code in different files,<br> we avoid duplication. We can keep our code clean and simple by just including the necessary files.\n\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n-----\n\n\n5.**\"How do you connect PHP to a database? Describe the process and provide an example.\"**\n\n\n\n---\n\n I made the connection to the database using XAMPP local server,<br> with my database name being **f21**:\n\n\n I first launched XAMPP and started the **Apache** and **MySQL** modules. Apache runs the local server,<br> while MySQL manages the database.\n\n After starting MySQL in XAMPP,<br> I went to **phpMyAdmin** (accessible via `http:\/\/localhost\/phpmyadmin\/`),<br> . I created a new database named **f21**. This is where I will store my data.\n\n\n\n![d1.PNG (https:\/\/cdn.steemitimages.com\/DQmcrkXsZ6qE5kJA8D4dV2gGEQ34xwufGM8M1Q65dNNWpyr\/d1.PNG)\n\n\n\n Next,<br> I wrote the PHP code to connect to the **f21** database. I used the following details:\n - **Server Name**: Since I am using XAMPP locally,<br> the server name is `localhost`.\n - **Username**: In XAMPP,<br> the default username for MySQL is `root`.\n - **Password**: There is no password set by default in XAMPP,<br> so I left it blank (`\"\"`).\n - **Database Name**: The name of my database is `f21`.\n I used the `mysqli` object in PHP to establish the connection. The code I wrote included the server name,<br> username,<br> password,<br> and database name.\n \n \n![p12.PNG (https:\/\/cdn.steemitimages.com\/DQmcgdVodwpbduC9Z1PZ4tkzERvoxGS75NCwTnhenhhsWDv\/p12.PNG)\n\n\n![p13.PNG (https:\/\/cdn.steemitimages.com\/DQmbYZAkgLfdPitRhrS4G5NrjozsxxFzsCaENfT2V6Ukw2t\/p13.PNG)\n\n \n After creating the connection,<br> I included a check to see if the connection was successful. If there was an error,<br> PHP would output an error message using `connect_error`. Otherwise,<br> it would display a success message:\n \n \n\n Finally,<br> I saved the PHP file in the `htdocs` folder inside the XAMPP directory. To test the connection,<br> I opened my browser and navigated to the file,<br> using `http:\/\/localhost\/BSIT\/database.php`. The script successfully connected to the database and displayed the message \"Connected successfully\".\n\nI did connection to my **f21** database using PHP on the XAMPP local server. The connection was established using the default settings of XAMPP for MySQL,<br> and I was able to manage and query the database through PHP code.\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n----\n\n### Section 2: Practice Questions :\n\n\n1.**-Page with include: Create a PHP page (learn.php) and use the include syntax to import the header,<br> navigation bar,<br> sidebar and footer.**\n\n\n**How I Created the Page Using `include` in PHP**\n\nTo create the `learn.php` page,<br> I used the `include` statement to separate the different sections of the webpage,<br> such as the header,<br> navigation bar,<br> sidebar,<br> and footer,<br> into individual PHP fils ,<br> helps in reusing the code and keeping the structure clean.\n\n\n|![s1-1.PNG (https:\/\/cdn.steemitimages.com\/DQmV1DchnCasSrQSBrfSxBacSQh3eeA7v7Qj7pc62nNzmZQ\/s1-1.PNG)|![s2.PNG (https:\/\/cdn.steemitimages.com\/DQmRUcRGjhkwmWLqGtTJbpq4kBt7ycvvuHMQxs2uXZ6yWir\/s2.PNG)|\n| - | - |\n\n|![s3.PNG (https:\/\/cdn.steemitimages.com\/DQmTmARMXP7YUTDsAWv66TAWsm4Kbx78eSpGw2DRAs9Fa4t\/s3.PNG)|![s4.PNG (https:\/\/cdn.steemitimages.com\/DQmcFdt2Z1y5kDb8Wisyd113oQvbwgwdirVihH6Tk7UDPBC\/s4.PNG)|\n| - | - |\n\n\nI created different files for each section:\n - `header.php` for the top header section.\n - `navbar.php` for the navigation bar.\n - `sidebar.php` for the sidebar section on the left.\n - `footer.php` for the footer at the bottom.\n\n In the `learn.php` file,<br> I used the `include` statement to add each of these components at their respective positions. This made it easy to structure the webpage by including each section in the main page.\n\n\n|![s5.PNG (https:\/\/cdn.steemitimages.com\/DQmau4dKsEdju1cX3M9uH6Y6EYZfzz5K5XN4pGAsWy7r2iF\/s5.PNG)|![s6.PNG (https:\/\/cdn.steemitimages.com\/DQmQunQSMDdZan1fFdQn8fVcL67RUEnx1EFjng68aHxCjQi\/s6.PNG)|\n| - | - |\n\n\n\n|![s7.PNG (https:\/\/cdn.steemitimages.com\/DQmcVf44UjKxZWsRYyxYMCcBqgiwtLc67U2UEP8E3sKN2V2\/s7.PNG)|![s8.PNG (https:\/\/cdn.steemitimages.com\/DQmV65zVPWHQu3hzMK8KDZA25hWgXprhTzxbeMEJA8x8KRP\/s8.PNG)|\n| - | - |\n\n![s9.PNG (https:\/\/cdn.steemitimages.com\/DQmdHzAQ3UnazLtH8YRWare7nyHZ3oaED6WCvmmwaAMLcwZ\/s9.PNG)\n\n\n I applied different background colors,<br> centered the text within each section,<br> and styled them to make the webpage look distinct and organized.\n\n\n\n\n\n- The navigation bar is displayed horizontally,<br> styled with no list markers.\n- The sidebar is positioned on the left with a vertical layout,<br> making it easy to navigate.\n- Each section has its own color and layout to differentiate it visually.\n\n\n\n![s10.PNG (https:\/\/cdn.steemitimages.com\/DQmcK361KJBVbQxvx6HqCGaQh4gTocGL4JWzLwdQYjGRbBn\/s10.PNG)\n\n![s11.PNG (https:\/\/cdn.steemitimages.com\/DQmR4nGBt6gE6Y4kEofsVyMEdD4FKzYESBJBFvKFxVm4Fdc\/s11.PNG)\n\n\n\nBy using `include`,<br> I can easily manage and update each section without having to modify the whole page every time!\n\n\n\n\n\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n\n2.**-Database for Registration Page: Create a database capable of storing the data for a registration page.**\n\n\n\n\nTo store user data for the registration page,<br> I created a new database in MySQL. Here's the step-by-step process I followed:\n\n\n\n\n![d1-1.PNG (https:\/\/cdn.steemitimages.com\/DQmcrkXsZ6qE5kJA8D4dV2gGEQ34xwufGM8M1Q65dNNWpyr\/d1-1.PNG)\n\n\n I first opened XAMPP and ensured that both **Apache** and **MySQL** servers were running.\n\n\n\n![d2.PNG (https:\/\/cdn.steemitimages.com\/DQmQqytnn7FeHnz2de2XQdzgdimTaHVmoA5SppBbHX56JRq\/d2.PNG)\n\n\n I opened my web browser (Google Chrome) and typed `localhost\/phpmyadmin` to access the **phpMyAdmin** interface.\n\n\n\n![d3.PNG (https:\/\/cdn.steemitimages.com\/DQmbnwVjHpsZLVo9KygQLewCPEuoEFmv7Eq9NSbwHdTEGWx\/d3.PNG)\n\n\n\n In phpMyAdmin,<br> I clicked on the \"New\" button to create a new database. I named this database **registration** to store the data from my registration page.\n\n\n\n![d4.PNG (https:\/\/cdn.steemitimages.com\/DQmXK4dhxp7rvLJ4vPgDizmQaWk7UyH4jrb4PK5HcUTh4WR\/d4.PNG)\n\n![d5.PNG (https:\/\/cdn.steemitimages.com\/DQmZa4Ag5B27YA8tiYUWXYgV9rhqu2xBz8S9vnVaQqn1wyt\/d5.PNG)\n\n\n Inside the **registration** database,<br> I created a new table named `users` with the following columns:\n - **ID** (Primary Key,<br> Auto Increment)\n - **Username** (VARCHAR,<br> to store usernames)\n - **Password** (VARCHAR,<br> to store passwords)\n - **Email** (VARCHAR,<br> to store user email addresses)\n\n I set appropriate lengths for each field,<br> ensuring that the **ID** was auto incremented so that it would generate automatically for each new user entry.\n\nAfter completing these steps,<br> my database was successfully set up,<br> and it's now ready to store the registration data!\n\n---\n\n\n\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n3.**-Registration Page: Create a PHP registration page to save the data of five students in a database.**\n\n\n\n---\n\n\n\n\n I started by designing a simple **HTML form** with two fields: **username** and **password**. This form collects the user's data and sends it to a PHP script for processing.\n\n\n![d6.PNG (https:\/\/cdn.steemitimages.com\/DQmNTyhps6hBZBgJmD1EPpMDq8tMEck1vc3bHz8xPqwQPdV\/d6.PNG)\n\n\n![d7.PNG (https:\/\/cdn.steemitimages.com\/DQmW3hRsmrkgGueGkFgvhF8PJ8Raqjesy32pVDykC2ijqr2\/d7.PNG)\n\n\n I created a PHP script (`register.php`) that connects to my MySQL database named `registration`. The script is responsible for processing the form data and saving it to the database.\n\n\n![d8.PNG (https:\/\/cdn.steemitimages.com\/DQmSxdKmQ4DYEMWTfQLsoZnombjxViCom1Lt1ndyUE9G8Tm\/d8.PNG)\n\n\n When the form is submitted,<br> the data for the **username** and **password** is sent to the PHP script using the `POST` method. I captured this data in PHP variables and used a prepared statement to insert it into the `users` table in the database.\n\n\n![d9.PNG (https:\/\/cdn.steemitimages.com\/DQmdfQ8gy5JVSn6nyRTdq4Z39KFAQBo48XtF6WvSHFUK9G5\/d9.PNG)\n\n\n I ensured that each new registration adds a row to the `users` table with the provided **username** and **password**. This way,<br> I could store the information of multiple users securely in the database.\n\n\n\n![d10.PNG (https:\/\/cdn.steemitimages.com\/DQmNbsn8iT39DrAeeEGYm2s2n9ghhhMY91to8Uh1U5WAgP8\/d10.PNG)\n\n\n\n After setting everything up,<br> I tested the registration page by entering different usernames and passwords. The PHP script successfully inserted the data into the database,<br> confirming the form was working correctly.\n\n---\n\n\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n\n4.**-Login Page: Create a PHP login page that verifies the login information with the ones stored in the database and redirects the user if successful.**\n\n\n\n\n\n---\n\n\n\nTo create the **PHP login page** that checks the **username** and **password** from the database,<br> I followed these steps:\n\n I started by creating an HTML form where users can enter their **username** and **password**. This form was simple,<br> having two input fields (for username and password) and a submit button. The form data is sent to a PHP script for validation.\n\n\n![f1.PNG (https:\/\/cdn.steemitimages.com\/DQmcy4E1cRopmXLT7qBpd7wYg9DAiBFUZhAYi4Aaybdzy7G\/f1.PNG)\n\n\n\n I created a PHP script (`login.php`) that connects to my MySQL database named `registration`. The script is responsible for verifying the user's credentials against the data stored in the database.\n\n\n\n![f2.PNG (https:\/\/cdn.steemitimages.com\/DQmNSMW1PY6ZKWZA9QASXVGYv9er2bVy6fsMr5bLFn3W9vY\/f2.PNG)\n\n![f3.PNG (https:\/\/cdn.steemitimages.com\/DQmNztD8eN9S7DK9FCNpBC4UUcHQWNTUvz3p5EMeGYzEfLw\/f3.PNG)\n\n\n When the user submits their **username** and **password**,<br> the form sends the data using the `POST` method to the PHP script. I captured this input in variables `$user` and `$pass`.\n\n\n\n![f4.PNG (https:\/\/cdn.steemitimages.com\/DQma3jHJq45LXwEqdHAsV6YgnC7v9YhndBFL6pCzbxRAzx9\/f4.PNG)\n\n\n I used a **prepared statement** in PHP to safely check if the entered **username** and **password** match any record in the `users` table in the database. If the username and password match an entry,<br> it means the user credentials are correct.\n\n\n\n![f5.PNG (https:\/\/cdn.steemitimages.com\/DQmeSdaTpVNW16xTbzXbMes3u2ysbUm8ynLqU5HgzvT1xWd\/f5.PNG)\n\n\n - If the credentials match,<br> the PHP script echoes: `\"Successfully logged in. Welcome home!\"`,<br> indicating the user has successfully logged in.\n\n\n - If the credentials don't match,<br> the script displays an error message: `\"Invalid username or password. Please try again.\"`\n\n\n I tested the login page by entering various combinations of usernames and passwords,<br> ensuring that the login system correctly identifies valid and invalid credentials. When the credentials were correct,<br> the message `\"Successfully logged in. Welcome home!\"` was displayed,<br> and for incorrect entries,<br> it showed incorrect password or email.\n\n---\n\n\n\n\n\n\nThat's it from today's blog I hope you will like it. With best wishes \u2764\ufe0f. Now I like to invite @ahsansharif,<br> @fombae and @josepha to participate in this amazing contest.\n\n# <center><a href=\"https:\/\/steemit.com\/submit.html\"><i>Thanks alot for reading \u2764\ufe0f\ud83e\udd17 .<\/i><\/a> <\/center>\n\n\n# <center><a href=\"https:\/\/steemit.com\/submit.html\"><i>[My introduction post (https:\/\/steemit.com\/hive-172186\/@hudamalik20\/my-achievement-1-or-14-august-2023-or-my-introduction-by-hudamalik20)<\/i><\/a> <\/center>\n\n\n\n<center><a href=\"https:\/\/steemit.com\/submit.html\"><i>Regards : @hudamalik20 .<\/i><\/a> <\/center>\n\n\n\n\n<\/div>\n\n![image.png (https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png)\n\n\n\n<div class=pull-right>\n\n\n\n\n<\/div>\n<\/div>",<br>"json_metadata":" \"tags\":[\"dynamicdevs-s20w4\",<br>\"burnsteem25\",<br>\"steemexclusive\",<br>\"pakistan\",<br>\"club5050\" ,<br>\"users\":[\"hudamalik20\",<br>\"starrchris\",<br>\"ahsansharif\",<br>\"fombae\",<br>\"josepha\" ,<br>\"image\":[\"https:\/\/cdn.steemitimages.com\/DQmR6c667d4BzWb3ETR8UJoTYSfFbeLhFcAsrqpZBaEmbvb\/Blue%20Geometric%20Business%20YouTube%20Thumbnail_20241002_101818_0000.png\",<br>\"https:\/\/cdn.steemitimages.com\/DQmZnSpLz8dhMCaFkH7ozKhPk5rY7E69YD3vUKjpQrprvZt\/image.png\",<br>\"https:\/\/cdn.steemitimages.com\/DQmUS1N7hxCJuiarpDiDxAj4o1XCBFPYJ4sRERKmj9oh9Qb\/p1.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmWJBLbLWP9rjH7kRtzwspRWi75fdxh8FzmSTULG4buHbT\/p2.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmZ4Lj5GAk2qUk8XDJL4KyxWPPW8dBnspSUN4xthShQJFG\/p3.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmbmqw84XEFXkr28bSFj5weNmmUKDDT8vBy34a924muXU4\/p4.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmYmCxouSU8dyPZUKBNPZ8MLnZ8WgsEap8tE7nV6atuaHx\/p5.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmZjQMdaQeHBDP5ZJWqjQHAb52cJncusWGXzYSVT88H5uF\/p6.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmaEHS55yQpM68ygyP2ktSS2y4KcMA7HuJGmX4zNgfKxgL\/p7.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmVS6FGWcj3KCr14eNpa2Er2irmNU6te9gKZWHVQkCp1mq\/p8.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmdqCNhEohLZm9bhgtMTVSUvgN5bpayFJsYGanLcy3MkGk\/p9.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmQr5FyS9b8hgXVxsLQeipSzF3xt2qoQTAZFFo16fGGggs\/p10.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmdsB3PvBiMrMKLVskLyhRAu8Zh7a4GoHd6uAKqEpLUVoX\/p11.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmcrkXsZ6qE5kJA8D4dV2gGEQ34xwufGM8M1Q65dNNWpyr\/d1.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmcgdVodwpbduC9Z1PZ4tkzERvoxGS75NCwTnhenhhsWDv\/p12.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmbYZAkgLfdPitRhrS4G5NrjozsxxFzsCaENfT2V6Ukw2t\/p13.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmV1DchnCasSrQSBrfSxBacSQh3eeA7v7Qj7pc62nNzmZQ\/s1-1.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmRUcRGjhkwmWLqGtTJbpq4kBt7ycvvuHMQxs2uXZ6yWir\/s2.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmTmARMXP7YUTDsAWv66TAWsm4Kbx78eSpGw2DRAs9Fa4t\/s3.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmcFdt2Z1y5kDb8Wisyd113oQvbwgwdirVihH6Tk7UDPBC\/s4.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmau4dKsEdju1cX3M9uH6Y6EYZfzz5K5XN4pGAsWy7r2iF\/s5.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmQunQSMDdZan1fFdQn8fVcL67RUEnx1EFjng68aHxCjQi\/s6.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmcVf44UjKxZWsRYyxYMCcBqgiwtLc67U2UEP8E3sKN2V2\/s7.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmV65zVPWHQu3hzMK8KDZA25hWgXprhTzxbeMEJA8x8KRP\/s8.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmdHzAQ3UnazLtH8YRWare7nyHZ3oaED6WCvmmwaAMLcwZ\/s9.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmcK361KJBVbQxvx6HqCGaQh4gTocGL4JWzLwdQYjGRbBn\/s10.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmR4nGBt6gE6Y4kEofsVyMEdD4FKzYESBJBFvKFxVm4Fdc\/s11.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmcrkXsZ6qE5kJA8D4dV2gGEQ34xwufGM8M1Q65dNNWpyr\/d1-1.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmQqytnn7FeHnz2de2XQdzgdimTaHVmoA5SppBbHX56JRq\/d2.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmbnwVjHpsZLVo9KygQLewCPEuoEFmv7Eq9NSbwHdTEGWx\/d3.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmXK4dhxp7rvLJ4vPgDizmQaWk7UyH4jrb4PK5HcUTh4WR\/d4.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmZa4Ag5B27YA8tiYUWXYgV9rhqu2xBz8S9vnVaQqn1wyt\/d5.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmNTyhps6hBZBgJmD1EPpMDq8tMEck1vc3bHz8xPqwQPdV\/d6.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmW3hRsmrkgGueGkFgvhF8PJ8Raqjesy32pVDykC2ijqr2\/d7.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmSxdKmQ4DYEMWTfQLsoZnombjxViCom1Lt1ndyUE9G8Tm\/d8.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmdfQ8gy5JVSn6nyRTdq4Z39KFAQBo48XtF6WvSHFUK9G5\/d9.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmNbsn8iT39DrAeeEGYm2s2n9ghhhMY91to8Uh1U5WAgP8\/d10.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmcy4E1cRopmXLT7qBpd7wYg9DAiBFUZhAYi4Aaybdzy7G\/f1.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmNSMW1PY6ZKWZA9QASXVGYv9er2bVy6fsMr5bLFn3W9vY\/f2.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmNztD8eN9S7DK9FCNpBC4UUcHQWNTUvz3p5EMeGYzEfLw\/f3.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQma3jHJq45LXwEqdHAsV6YgnC7v9YhndBFL6pCzbxRAzx9\/f4.PNG\",<br>\"https:\/\/cdn.steemitimages.com\/DQmeSdaTpVNW16xTbzXbMes3u2ysbUm8ynLqU5HgzvT1xWd\/f5.PNG\" ,<br>\"links\":[\"https:\/\/steemit.com\/submit.html\",<br>\"https:\/\/steemit.com\/hive-172186\/@hudamalik20\/my-achievement-1-or-14-august-2023-or-my-introduction-by-hudamalik20\" ,<br>\"app\":\"steemit\/0.2\",<br>\"format\":\"markdown\" "
comment_options
"author":"hudamalik20",
"permlink":"sec-s20w4-or-introduction-to-php-part-2",
"max_accepted_payout":"1000000.000 SBD",
"percent_steem_dollars":10000,
"allow_votes":true,
"allow_curation_rewards":true,
"extensions":[[0,
"beneficiaries":[ "account":"null",
"weight":2500
* The API used to generate this page is provided by @steemchiller.