Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript and php errors causing application not to work
    primarykey
    data
    text
    <p>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:</p> <pre><code>Syntax Error: missing ; before statement: Notice: undefined variable courseDatas in ..... line 28 </code></pre> <p>The other error I am getting is a mysqli/php error which states:</p> <pre><code>Warning: array_push() expects parameter 1 to be array, ... on line 247 </code></pre> <p>How can both these errors be removed?</p> <p><strong>Javascript:</strong> </p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready( function(){ var coursedatas = &lt;?php echo json_encode($courseDatas); ?&gt;; //error here $('#coursesDrop').change(function() { var courseId = $(this).val(), coursedata; for (var i = 0, l = coursedatas.length; i &lt; l; i++) { if (coursedatas[i].courseId = courseId) { coursedata = coursedatas[i]; } } var index = $('#newDuration option[value="' + courseData.Duration + '"]').index('#newDuration option'); $('#newDuration')[0].selectedIndex = index; }); }); &lt;/script&gt; </code></pre> <p>.....</p> <p><strong>PHP:</strong></p> <pre><code>$coursequery = " SELECT CourseId, CourseNo, CourseName, Duration FROM Course ORDER BY CourseNo "; $courseqrystmt=$mysqli-&gt;prepare($coursequery); // You only need to call bind_param once $courseqrystmt-&gt;execute(); $courseqrystmt-&gt;bind_result($dbCourseId,$dbCourseNo,$dbCourseName,$dbDuration); $courseqrystmt-&gt;store_result(); $coursenum = $courseqrystmt-&gt;num_rows(); $courseHTML = ''; $courseHTML = '&lt;select name="courses" id="coursesDrop"&gt;'.PHP_EOL; $courseHTML .= '&lt;option value=""&gt;Please Select&lt;/option&gt;'.PHP_EOL; while ( $courseqrystmt-&gt;fetch() ) { $courseHTML .= sprintf("&lt;option value='%s'&gt;%s - %s&lt;/option&gt;", $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 .= '&lt;/select&gt;'; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload