Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:52:43+00:00 2026-06-15T08:52:43+00:00

I am getting two sets of errors I can;t seem to figure out. One

  • 0

I am getting two sets of errors I can;t seem to figure out. One is a error in my javascript in my error console stating:

Syntax Error: missing ; before statement:
Notice: undefined variable courseDatas in ..... line 28

The other error I am getting is a mysqli/php error which states:

Warning: array_push() expects parameter 1 to be array, ... on line 247

How can both these errors be removed?

Javascript:

<script type="text/javascript">
    $(document).ready( function(){
        var coursedatas = <?php echo json_encode($courseDatas); ?>; //error here
        $('#coursesDrop').change(function()
        {
            var courseId = $(this).val(),
            coursedata;
            for (var i = 0, l = coursedatas.length; i < l; i++)
            {
                if (coursedatas[i].courseId = courseId) { coursedata = coursedatas[i]; }
            }
            var index = $('#newDuration option[value="' + courseData.Duration + '"]').index('#newDuration option');
            $('#newDuration')[0].selectedIndex = index;
        });
    });
</script>

…..

PHP:

$coursequery = "
    SELECT CourseId, CourseNo, CourseName, Duration
    FROM Course
    ORDER BY CourseNo
";

$courseqrystmt=$mysqli->prepare($coursequery);
// You only need to call bind_param once

$courseqrystmt->execute();   
$courseqrystmt->bind_result($dbCourseId,$dbCourseNo,$dbCourseName,$dbDuration);
$courseqrystmt->store_result();
$coursenum = $courseqrystmt->num_rows();     
$courseHTML = '';
$courseHTML = '<select name="courses" id="coursesDrop">'.PHP_EOL;
$courseHTML .= '<option value="">Please Select</option>'.PHP_EOL;           

while ( $courseqrystmt->fetch() ) {
    $courseHTML .= sprintf("<option value='%s'>%s - %s</option>", $dbCourseId,$dbCourseNo,$dbCourseName) . PHP_EOL;  
    $courseData = array();
    $courseData["CourseId"] = $dbCourseId;
    $courseData["CourseNo"] = $dbCourseNo;
    $courseData["CourseName"] = $dbCourseName;
    $courseData["Duration"] = $dbDuration;

    array_push($courseDatas, $courseData); //error here
}    
$courseHTML .= '</select>';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:52:44+00:00Added an answer on June 15, 2026 at 8:52 am

    The $courseDatas variable needs to be defined outside of your while loop as an array.

    EDITED – HERE IS WHAT YOUR SCRIPT NEEDS TO LOOK LIKE:

    $coursequery = "SELECT CourseId, CourseNo, CourseName, Duration FROM Course
    ORDER BY CourseNo";
    $courseqrystmt=$mysqli->prepare($coursequery);
    // You only need to call bind_param once
    $courseqrystmt->execute();
    $courseqrystmt->bind_result($dbCourseId,$dbCourseNo,$dbCourseName,$dbDuration);
    $courseqrystmt->store_result();
    $coursenum = $courseqrystmt->num_rows();
    $courseHTML = '';
    $courseHTML = '<select name="courses" id="coursesDrop">'.PHP_EOL;
    $courseHTML .= '<option value="">Please Select</option>'.PHP_EOL;
    $courseDatas = array();
    while ( $courseqrystmt->fetch() ) {
        $courseHTML .= sprintf("<option value='%s'>%s - %s</option>",$dbCourseId,$dbCourseNo,$dbCourseName) . PHP_EOL;
        $courseData = array();
        $courseData["CourseId"] = $dbCourseId;
        $courseData["CourseNo"] = $dbCourseNo;
        $courseData["CourseName"] = $dbCourseName;
        $courseData["Duration"] = $dbDuration;
        array_push($courseDatas, $courseData); //error here
    }
    $courseHTML .= '</select>';
    
    <script type="text/javascript">
        $(document).ready( function(){
            var coursedatas = '<?=json_encode($courseDatas);?>';
            //now we have established some data for the $courseDatas array!
            $('#coursesDrop').change(function()
            {
                var courseId = $(this).val(), coursedata;
                for (var i = 0, l = coursedatas.length; i < l; i++)
                {
                    if (coursedatas[i].courseId = courseId) { coursedata = coursedatas[i]; }
                }
                var index = $('#newDuration option[value="' + courseData.Duration + '"]').index('#newDuration option');
                $('#newDuration')[0].selectedIndex = index;
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting two errors, both revolving around encoding and both related. The first error
There are two sets of javascript SDK code, the one given on the SDK
I am getting two types of errors that I don't know how to fix.
I am getting two console warnings: log4j:WARN No appenders could be found for logger
MessageBox.Show((some_string.Length).ToString); I am getting two errors for this: The best overloaded method match for
I'm getting the following two errors when loading my page: Notice: Undefined variable: realtor
I am getting two different sets of values when I try to calculate the
1.Initially created two sets. 2.Added elements to one set. 3.Assigned one set to another.
I'm probably making a newbie mistake here, but I can't figure out how to
I am getting two errors in code block which I am not able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.