Page 1 of 1

Notice: Undefined index: and Notice: Undefined variable:

Posted: Mon Feb 20, 2012 7:02 am
by ShadowSkill

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
	require 'config.php';
	$CourseID = $_GET['CourseID'];

	
	$res=mysql_query("SELECT * FROM  `course` WHERE  `CourseID`= '$CourseID' ");
	while($row_array = mysql_fetch_array($res, MYSQL_ASSOC))
	{
		$CourseTitle= $row_array['CourseTitle'];
		$CourseDescr= $row_array['CourseDescr'];
		$CourseID= $row_array['CourseID'];
    
	}
	require 'closeDB.php';
?>
<form id="form1" name="form1" method="post" action="editCourse.php">
  <p>
    <label>Course Title
      <input type="text" name="CourseTitle" id="CourseTitle" value="<?php echo $CourseTitle; ?>" />
    </label>
  </p>
  <p>
    <label>Course Description
      <textarea name="CourseDescr" id="CourseDescr" cols="45" rows="5"><?php echo $CourseDescr; ?></textarea>
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="AddCourse" id="AddCourse" value="Update Course" />
    </label>
  	<input type="hidden" name="eKO" id="eKO" value="1" /><input type="hidden" name="courseid" id="courseid" value="<?php print $CourseID; ?>" /></p>
</form>
<?php
	
	if ( array_key_exists ( 'eKO', $_POST )  ) 
	{
		require 'config.php';
		$CourseTitle=$_POST['CourseTitle'];
		$CourseDescr=$_POST['CourseDescr'];

		$func=mysql_query(" UPDATE  `course` SET  `CourseTitle` =  '$CourseTitle',`CourseDescr` =  '$CourseDescr' WHERE  `course`.`CourseID` =1;");
		
		if (!$func) 
			die('Error: ' . mysql_error());
		else
			print "Course Succesfuly Updated";
			
		require 'closeDB.php';
		
	}
?>
</body>
</html>

Notice: Undefined index: CourseID in C:\xampp\htdocs\courserecord\editCourse.php on line 11
Notice: Undefined variable: CourseTitle in C:\xampp\htdocs\courserecord\editCourse.php on line 27
Notice: Undefined variable: CourseDescr in C:\xampp\htdocs\courserecord\editCourse.php on line 32

My cousin fixed my system but i can't figure out this lines. =/
My cousin is away right now on a business trip.

Re: Notice: Undefined index: and Notice: Undefined variable:

Posted: Mon Feb 20, 2012 7:09 am
by Celauran
You're trying to use variables that may not exist. What if $_GET['CourseID'] doesn't exist? Your whole page falls apart. Take a look at isset()

Re: Notice: Undefined index: and Notice: Undefined variable:

Posted: Tue Feb 21, 2012 5:53 am
by phpfresher
dont ever try to use the variable that is not initialized, if you want to use better user isset() or empty to check for thier value.