Error: TypeError: Cannot read properties of undefined (reading ‘text’)

I have a simple form that is supposed to be saved in applicant_need table in the database. my fields are (coursetype, course_need, c_name, total). but whenever I try to submit it doesnt work I get a server error 500 then it tells me “Cannot read properties of undefined (reading ‘text’)”
here’s my html

           <form id='addneed' class="intro-y box grid-cols-1 p-5">
         
                <div class="grid grid-cols-1 gap-4 row-gap-5 mt-5">
                                           
                    <div class="intro-y col-span-12 sm:col-span-4 px-2">

                        <div class="mb-2">Course Type</div>
                        <select name="coursetype" onchange="course_type_handler()" id="course_type_id" class="input w-full border flex-1 " required="">
                            <option">Choose an option</option>
                            <?php $x = 1;
                            if ($course_types->num_rows > 0) {
                                while ($rowm = $course_types->fetch_assoc()) { ?>
                                    <option value="<?php echo $rowm['id']; ?>"><?php echo $rowm['name']; ?></option>
                            <?php }
                            } ?>
                        </select>
                    </div>
            
            <div class="intro-y col-span-12 sm:col-span-4 px-2">
                        <div class="mb-2">Courses Need</div>
                        <select name='course_need' id="select_courses_id"  class="input w-full border flex-1 " required="">
                            <option >Choose an option</option>
            
                
                        </select>
                    </div>

    <div class="intro-y col-span-12 sm:col-span-4 px-2">

                        <label>Other</label>
<br>
<div>
                        <input type="radio" name='others'   onchange="radio_extra_handler()" class="input w-full border flex-1" >

                    </div>     

                    </div>  
<br>
<div class='intro-y col-span-12 sm:col-span-4 px-2' name='extra'  id="extra" style='display: none;'>
                        
                        <div class="mb-2">Course Name</div>
                        <input name='c_name'   type="text" class="input w-full border flex-1"  placeholder="Enter course name">
                   
                   
                        <div class="mb-2">Total</div>
                        <input name='total'  type="number"  class="input w-full border flex-1" placeholder="Enter number of nominees">
                    

 </div>                               

    
                    

                </div>

                <div style="display: flex; justify-content: center; margin-top: 20px;">
                    <button required type="submit" class=" button text-white bg-theme-1 shadow-md mr-2">Submit</button>
                </div>



            </div>


      
</form>


js script

<script>
function handleErrors(response) {
    if (response?.ok) {
  console.log('Use the response here!');
} else {
  console.log(`HTTP Response Code: ${response?.status}`)
}}
   // Function to handle form submission
        function handleSubmit(event) {
            // Prevent the default form submission behavior
            event.preventDefault();

            // Get form elements and their values
            const form = event.target;
            const formData = new FormData(form);
            
            // Convert FormData to an object
            const formObject = {};
            formData.forEach((value, key) => {
                formObject[key] = value;
            });

             // Send form data to a PHP file using the Fetch API
            fetch('server/add_needs_server.php', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(formObject),
            })
         .then(handleErrors)
            .then(response =>  response.text())  // I believe the issue start here
            .then(data => {

        console.log(document.getElementById('course_type_id').value);
        console.log(document.getElementById('select_courses_id').value);

                if(data == "Inserted"){

            var coursename = document.querySelector('select[name=course_need]').value;
                    var message = document.querySelector('.message');
                    var response = document.querySelector('.response');

                    message.innerHTML = alert( 'your request has been submitted' );

                    message.classList.remove('failed');
                    message.classList.add('success');
                    response.classList.remove("hide");

                    document.getElementById("addneed").reset();


                } else {
                    var coursename = document.querySelector('select[name=course_need]').value;
                    var message = document.querySelector('.message');
                    var response = document.querySelector('.response');

                    message.innerHTML =  alert( 'Failed to upload' + coursename  );

                    message.classList.remove('success');
                    message.classList.add('failed');
                    response.classList.remove("hide");



                   
                                   }
                //console.log('Server response:', data);
                // You can handle the text response as needed, e.g., display it on the page
            })
            .catch(error => {
                console.error('Error:', error);
            });
        }

        // Get the form element and add a submit event listener
        const myForm = document.getElementById('addneed');
        myForm.addEventListener('submit', handleSubmit);
    </script>


Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật