Hero background

PHP to Update MySQL

Technology • Year Year 11 • 70 • 17 students • Created with AI following Aligned with Australian Curriculum (F-10)

Technology
1Year Year 11
70
17 students
4 August 2024

Teaching Instructions

PHP statements used to update a MySQL database

PHP to Update MySQL

Lesson Duration: 70 minutes

Year Level: Year 11

Subject: Technologies (Digital Technologies)

Curriculum Area: Australian Curriculum: Technologies

Specific Focus:

  • PHP statements
  • MySQL database updates

Class Context: 17 students


Objectives

By the end of this lesson, students will:

  1. Understand basic PHP syntax.
  2. Be able to write and execute PHP statements to update records in a MySQL database.
  3. Recognise the real-world applications of PHP and MySQL in web development.

Materials Required

  • Computers with internet access
  • XAMPP or WAMP installed
  • Text editor (such as Visual Studio Code)
  • Preconfigured MySQL database (sample database provided)

Lesson Structure

1. Introduction (10 minutes)

  • Attendance and Housekeeping (2 minutes)

  • Lesson Overview (3 minutes)

    • Discuss today's objectives and the importance of PHP and MySQL in technology and web development.
  • Engage Students with a Quick Quiz (5 minutes)

    • Use Kahoot! or another interactive tool for a 5-question quiz on PHP basics to assess prior knowledge.

2. Explanation and Demonstration (20 minutes)

  • Brief Recap of PHP Basics (5 minutes)

    • Quick refresher on PHP syntax and opening/closing tags.
    <?php
    // Your code here
    ?>
    
  • Introduction to MySQL Database (5 minutes)

    • Explain tables, rows, and columns.
    • Introduce the sample database structure (provide a printed diagram).
  • PHP to Update MySQL (10 minutes)

    • Demonstrate the process of writing a PHP script to update database records.
    • Live coding example to show updating a row in the database.
    <?php
    // Database credentials
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "school";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }
    
    // SQL update statement
    $sql = "UPDATE students SET favourite_subject='Digital Technologies' WHERE id=1";
    
    if ($conn->query($sql) === TRUE) {
      echo "Record updated successfully";
    } else {
      echo "Error updating record: " . $conn->error;
    }
    
    $conn->close();
    ?>
    

3. Guided Practice (15 minutes)

  • Hands-On Activity: Implementing PHP Update Statements (15 minutes)
    • Distribute a preconfigured MySQL database and guide students to:
      1. Establish a connection to the database using PHP.
      2. Write PHP code to update specific records.
      3. Execute and test their scripts.
    • Move around the classroom to provide individual support and answer questions.

4. Independent Practice (15 minutes)

  • PHP Challenge: Update Multiple Fields (15 minutes)
    • Challenge students to write PHP code that updates multiple fields for a given record. For instance, updating both favourite_subject and grade.
    • Students should test their code and print output to show successful updates.

5. Conclusion (10 minutes)

  • Review and Recap (5 minutes)

    • Summarise key points from the lesson:
      1. PHP syntax for MySQL updates.
      2. Importance of error handling in database operations.
      3. Real-world applications.
  • Q&A Session (5 minutes)

    • Open the floor to any final questions students might have.
  • Homework Assignment

    • Students are to create a PHP script to update a different dataset in the MySQL database and prepare a short report (one page) explaining their approach.

Assessment

  • Formative: Observations during hands-on and independent practice sessions.
  • Summative: Evaluation of the completed PHP script and written report for homework.

Differentiation

  • Advanced Learners: Provide additional challenges such as implementing form-based updates.
  • Struggling Learners: Offer simplified tasks and one-on-one support.

Reflection

  • Post-Lesson Review: Assess the effectiveness of the lesson and make note of any adjustments needed for future lessons.

This lesson plan is crafted specifically to align with the Australian Curriculum and cater to the needs of Year 11 students, ensuring they gain practical skills in PHP and MySQL database management. Teachers can adapt this framework based on individual classroom dynamics and student proficiency levels.

Create Your Own AI Lesson Plan

Join thousands of teachers using Kuraplan AI to create personalized lesson plans that align with Aligned with Australian Curriculum (F-10) in minutes, not hours.

AI-powered lesson creation
Curriculum-aligned content
Ready in minutes

Created with Kuraplan AI

🌟 Trusted by 1000+ Schools

Join educators across Australia