0

My web page was working fine last week and when I went to work on it again I got this:
Notice: Undefined index: courseID in C:\wamp\www\1.1\lib\coursePage.php.inc on line 7

Notice: Trying to get property of non-object in C:\wamp\www\1.1\lib\coursePage.php.inc on line 10
we have no data

Here is my coursePage.php.inc

<?php
/**
*/

class coursePage extends webPage {
	protected function content() {
		$courseID = $_GET['courseID'];
		$query = "SELECT * FROM courses WHERE courseID=$courseID";
		$result  = query($query);
		if($result->num_rows > 0) {
			$temp = $result->fetch_assoc();
		}
		else {
			echo "we have no data";
			exit;
		}
?>

Any Ideas?

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by blocblue
0

You're getting the value courseID from the URL. If this value isn't set, you'll get the notice you're seeing.

To overcome this, you could use:

$courseID = ( isset( $_GET['courseID'] ) ? $_GET['courseID'] : 0 );

This is basically an if - else statement in one line if you've not seen it before. Otherwise known as a ternary operator.

Best,

R.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.