SEC S20W4|| Introduction to PHP Part -2steemCreated with Sketch.

in Teachers & Studentslast month (edited)

🌟 Enhancing My PHP Development Skills 🌟

Hey friends! I’ve come across an exciting challenge that I’m eager to join this week. It’s called Introduction to PHP Part - 2, hosted by @starrchris. You can find more details and participate through this link: SEC S20W4 | Introduction to PHP Part - 2.

Cream Colorful Illustrative English Class Presentation.png
Image Source: canva


🔍 Section 1: Theoretical Questions

🚀 Understanding Exceptions in PHP

Exceptions in PHP help manage errors gracefully, allowing your applications to handle unexpected situations without crashing. Here's a basic example of using try and catch blocks to manage a division by zero error:

Division by Zero Error:

Handling Division by Zero Error
Image Placeholder: Handling Division by Zero Error

2.JPG
Image Placeholder: Result when dividing by zero

When dividing with a non-zero number, there is no error:
3.JPG
Image Placeholder: Example of successful division

4.JPG
Image Placeholder: Result of successful division

⚠️ Six Types of Errors in PHP

  1. Parse Error:
    These occur due to syntax errors in your code.
    Parse Error Example
    Image Placeholder: A common parse error

    6.JPG
    Image Placeholder: Output of code

  2. Fatal Error:
    Stops script execution due to critical issues, such as calling undefined functions.
    Fatal Error Example
    Image Placeholder: Example of a fatal error

    8.JPG
    Image Placeholder: Output of code

  3. Warning:
    Indicates potential problems without halting script execution.
    Warning Example
    Image Placeholder: A warning message indicating a non-critical issue

    10.JPG
    Image Placeholder: Output of code with warning

  4. Notice:
    Alerts about less severe issues, often related to variables.
    Notice Example
    Image Placeholder: A notice about variable usage

    13.JPG
    Image Placeholder: Output of code with notice

  5. Deprecated:
    Indicates the use of deprecated functions or features that may be removed in future PHP versions.
    Example:

    
    <?php
    if (ereg("pattern", $string)) {
        // do something
    }
    ?>
    

    Output: Deprecated: Function ereg() is deprecated.

  6. Strict:
    Suggests changes to code that may cause issues in future PHP versions.
    Example:

    
    <?php
    
    function myFunction(
    ) {
        return;
    }
    $result = myFunction() + 5;
    ?>
    

    Output: Strict Standards: Only variables should be passed by reference.

🧩 Personal Errors and Lessons Learned

Errors are part of the learning process. Here are three personal examples from my development journey:

Real-World Algorithm: Student Grade Processing System

Building a student grade processing system offers rich learning opportunities. Let's explore common errors faced:

Student Grade Processing System Diagram
Image Placeholder: Diagram illustrating the student grade processing system

  1. Division by Zero Error:
    Why does the error show? When I pass an empty array, count($student['grades']) will be 0, thus causing the division by zero error.

15.JPG
Image Placeholder: Caught in action: Division by zero error

Capture1.JPG
Image Placeholder: Image of error message for Division by Zero

16.JPG
Image Placeholder: Solution for Division by Zero error

  1. Undefined Array Key Error:
    Why does the error show? If we try to access a student that doesn't exist, we'll get an undefined array key error.

17.JPG
Image Placeholder: Error indicating an undefined array key

18.JPG
Image Placeholder: Error message for Undefined Array Key

19.JPG
Image Placeholder: Solution for Undefined Array Key error

  1. Incorrect Argument Passing:

21.JPG

Image Placeholder: Error due to incorrect argument passing

22.JPG
Image Placeholder: Image of error message for Incorrect Argument Passing

23.JPG
Image Placeholder: Solution for Incorrect Argument Passing

🔗 Includes and Their Importance

The include statement in PHP allows you to incorporate code from one file into another, promoting reusability.

Example of Using Include:


// header.php
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>My Website</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
    </header>
</body>
</html>

// footer.php
<footer>
    <p>&copy; 2024 My Website</p>
</footer>

🌐 Database Connection Example

Connecting to a database using PDO is crucial for data management

. Here’s how it’s done:


<?php
$host = 'localhost';
$dbname = 'mydb';
$username = 'user';
$password = 'password';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
?>

Here's your content with the Image Placeholder format added for each image, positioned below the images as requested:


🔍 Section 2: Practice Questions

📚 Page with Include

Let’s create a learn.php page using includes to enhance maintainability.

Learn Page Structure
Image Placeholder: Footer included in the learn page.

navbat.JPG
Image Placeholder: Navbar included in the learn page.

Learn Page Header
Image Placeholder: Header included in the learn page.

Learn Page Sidebar
Image Placeholder: Sidebar content for easy navigation.

Main Content of Learn Page
Image Placeholder: The main content of the learn page.

Final Layout of Learn Page
Image Placeholder: Final layout showcasing all components.

🗄️ Database Setup for Registration Page

First, configure the database:

Database Configuration
Image Placeholder: Database configuration settings.

Then, create the students table:

Database Structure
Image Placeholder: Structure of the students table in the database.

👤 Registration Page

Here’s a glimpse of the registration page for new students:

register code.JPG
Image Placeholder: Registration code for the page.

Registration Page Design
Image Placeholder: User-friendly registration page design.

Successful Registration Message

Successful Registration
Image Placeholder: Success message displayed after registration.

Database View Post-Registration

Database After Registration
Image Placeholder: Database view after saving five students.

🔑 Login Page

Here’s the login page that verifies user credentials:

Login Code
Image Placeholder: Login code for verification.

Login Page Design
Image Placeholder: Simple and effective login page design.

Bonus: Redirecting to Welcome Page

Redirect Code
Image Placeholder: Code for redirecting to welcome page.

Welcome Page
Image Placeholder: Welcome page displayed after a successful login.


🎉 Conclusion

This showcase demonstrates the process of developing a PHP-based application, highlighting best practices, error handling, and effective design strategies. Each component plays a critical role in creating a seamless user experience.


I want to invite @khiwa , @shovro and @fauziah95 join the contest.


My introduction post on Steemit: link


About the Author

👋 Hi, I’m Kafio!
Software Engineer | Data Science Enthusiast | Trading Buff | Development Geek | Computer Science Lover 💻📊📈

I’m passionate about exploring the intersection of technology and innovation, with a special interest in data science, trading, and software development. Whether it’s diving into the latest in computer science or developing new projects, I’m always excited to learn and share insights. 🚀

I also love to travel

Got questions or just want to connect? Feel free to reach out to me at: [email protected] 🌟

image00001.jpeg

Sort:  
Loading...
 last month 

Hi @kafio you have presented everything well and in order. Your PDO method to connect the database and PHP file is good. Great job while creating and linking the login page. Your work is appreciative. Best wishes.

 last month 

Thank you so much for your kind word! I really appreciate your feedback on my PDO method and the login page. It’s always great to hear that my efforts are recognice. If you have any suggestions or tips for improvement, I’d love to hear them. Best wishes to you too!

 last month 

the post is shared on Twitter: Twitter Link.

zerze.JPG

 last month 

Thank you very much for publishing your post in Teachers and Students community

DescriptionInformation
Verified User
Plagiarism Free / AI Article Free
#steemexclusive
350+ Words
#club5050
Bot Free

Beneficiaries

#burnsteem25
@ myteacher

no
no

Thank you for making a handy post in our community, we hope the verification from the teaching team will be more detailed to assess your post.

Good luck with your participation.

 last month 

thank you for your feedback

Omar, my friend, as you've been telling us that programming is your world, I believe that you do understand this class well. I don't have sufficient knowledge on this subject, so I don't know what to comment on this article of yours. I wish you the best of luck, my friend. I am happy to see you have found joy and are growing on Steem.

Keep up the energy.

 last month 

Thank you, my friend! I won't forget you helping me grow on Steemit.

No problem. Enjoy the journey and keep the spirit level good.

 last month 

Hello @kafio I liked your post improving PHP skills. Your examples about errors, like division by zero, are really clear and helpful.

Yes it would be great if you could add a video to show how your code works.Wish you best of luck 🤗🌼🌸

 last month 

Thanks a lot for your nice comment! I’m super happy you liked the examples, they were fun to make. 😊 I think adding a video would be a cool idea, I’ll try to do that next time! Wishing you the best too! 🌼🌸

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.029
BTC 76511.74
ETH 3031.28
USDT 1.00
SBD 2.62