Uncaught Error: Trying to set attributes URGENT HELP

Warning: Undefined variable $courseObj in C:\Users\dabya\OneDrive\Documents\xamp\htdocs\projectV2\ManageCourse.php on line 26

Fatal error: Uncaught Error: Call to a member function updateCourse() on null in C:\Users\dabya\OneDrive\Documents\xamp\htdocs\projectV2\ManageCourse.php:26 Stack trace: #0 {main} thrown in C:\Users\dabya\OneDrive\Documents\xamp\htdocs\projectV2\ManageCourse.php on line 26


<?php

include 'Header.php';

$CourseObj= new Courses();

if (isset($_GET['ID']))

        {

            $cID = $_GET['ID'];

            $CourseObj->initWithCID($cID);

        }  

    $courseid=    $CourseObj->getCourseID();

    $coursename=    $CourseObj->getCourseName();

if (isset($_POST['editCourse']))

{

    //check if ID changed

    if (isset($_POST['CID']) == $courseid)

    {

        $editedName = $_POST['CName'];

        echo $editedName;

        $CourseObj->initWithCID($courseid);

        $CourseObj->setCourseID($courseid);

        $CourseObj->setCourseName($editedName);

        $courseObj->updateCourse();

    } elseif (isset($_POST['CID']) == $courseid) {

        echo "Cannot change Course ID";

    }

} elseif (isset($_POST['deleteCourse']))

{

    echo ("cool");

}

   ?>

Php variables are case-sensitive. $courseObj is not the same as $CourseObj. I recommend that you only use lower case for variable names and use an underscore _ to separate words within a name.

2 Likes

thank you so much, can you also check out the recent topic! youre very helpful

Sponsor our Newsletter | Privacy Policy | Terms of Service