Notice: Undefined index PHP error-Collection of common programming errors

This line:


is giving me the undefined index error. But I don’t understand why that is giving me an error when other queries don’t. Here’s the query I used. This is all made in Dreamweaver

mysql_select_db($database_project, $project);
$query_stuCompSci = "SELECT compsci.CSid FROM compsci WHERE NOT EXISTS  ( SELECT      studentcourses.Cid FROM studentcourses WHERE studentcourses.Cid=compsci.CSid )";
$stuCompSci = mysql_query($query_stuCompSci, $project) or die(mysql_error());
$row_stuCompSci = mysql_fetch_assoc($stuCompSci);
$totalRows_stuCompSci = mysql_num_rows($stuCompSci);

In the query, the table studentcourses has two columns (Sid, Cid) and the 2nd table compsci has two columns as well (CSid, Credits).

The query gets whatever Cid does not exist in student courses and when I test the query it works fine, however, when I try to see my website live it gives me the index error. If need be, I can copy my whole code in here but it about 220 lines long.

  1. Your query contained:

    SELECT compsci.CSid FROM ...
    

    Note the query is CSid, not Cid

  2. it mean that you havent selected Cid in query try

     "SELECT compsci.Cid,compsci.CSid FROM compsci WHERE NOT EXISTS  ( SELECT      studentcourses.Cid FROM studentcourses WHERE studentcourses.Cid=compsci.CSid )";
    
  3. You are calling Cid in Php

    
    

    but haven’t selected Cid in query. Do this

    SELECT compsci.Cid,compsci.CSid FROM ....
    

Originally posted 2013-11-09 23:31:45.