user1865192
user1865192

Reputation: 1

Notice: Undefined index PHP error

This line:

<?php echo $row_stuCompSci['Cid']; ?>

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.

Upvotes: 0

Views: 422

Answers (3)

Mudassir Hasan
Mudassir Hasan

Reputation: 28741

You are calling Cid in Php

<?php echo $row_stuCompSci['Cid']; ?>

but haven't selected Cid in query. Do this

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

Upvotes: 0

akatakritos
akatakritos

Reputation: 9858

Your query contained:

SELECT compsci.CSid FROM ...

Note the query is CSid, not Cid

Upvotes: 4

NullPoiиteя
NullPoiиteя

Reputation: 57312

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 )";

Upvotes: 1

Related Questions