4 Replies - 583 Views - Last Post: 14 May 2012 - 12:13 PM Rate Topic: -----

#1 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

undefined index error?

Posted 14 May 2012 - 10:32 AM

hi guys,
i have problem in my code
i wanna to check if the teacher rate the course or or not
if he rate not allow to rate again

this is my code
<title>Subject Matrix</title>
 <link rel="stylesheet" type="text/css"
href="styles.css"/>
<?php
session_start();
$teacher=$_SESSION['user'];

$conter=0;
foreach($_POST as $key=>$value)
{
	//and $value<>""
	if($key<>'teacher' )
	{
		include('con-db.php');
		$sql="insert into sub_matrix(code_Name,Teach_rate,id_Num)values('$key','$value',$teacher)";	
		$query=mysql_query($sql);
	$conter++;
	}
}
echo"<br>";
			echo"<br>";
			echo"<div align='center'>";
echo "<font size = '5'  color='#5A3A0B'>You rate ".$conter." course<br/></font>";
echo"<br>";
echo "<a href='Subject-matrix.php'>Return</a>";
?>

and i add the function for check like this
<?php
session_start();
$teacher=$_SESSION['user'];

include('con-db.php');


$conter=0;
foreach($_POST as $key=>$value)
{
	//and $value<>""
	if($key<>'teacher' )

	{
		if(Isselect($_REQUEST['id_Num'],$_REQUEST['code_Name']))
		{
		echo "the teacher ".$_REQUEST['id_Num']. " is rated  already";
	}
else
{
		$sql="insert into sub_matrix(code_Name,Teach_rate,id_Num)values('$key','$value',$teacher)";	
		$query=mysql_query($sql);
	$conter++;
	}
	}
}

echo"<br>";
			echo"<br>";
			echo"<div align='center'>";
echo "<font size = '5'  color='#5A3A0B'>You rate ".$conter." course<br/></font>";
echo"<br>";
echo "<a href='Subject-matrix.php'>Return</a>";
function Isselect($teacher,$key)
	{
		$sql="select * from  sub_matrix where id_Num =".$teacher." and code_Name='".$key."'";
		$query=mysql_query($sql);
		$num=mysql_num_rows($query);
		if ($num>0)
			return true;
		else
			return false;		
	}
?>


the error are undefined index
Notice: Undefined index: id_Num

Notice: Undefined index: code_Name in
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in
i try to solve but i can't :helpsmilie: :helpsmilie:
can you help me plz ?

Is This A Good Question/Topic? 0
  • +

Replies To: undefined index error?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,146
  • Joined: 08-June 10

Re: undefined index error?

Posted 14 May 2012 - 12:04 PM

check whether the data you want to access really exist. you can use the isset() function for that.
Was This Post Helpful? 0
  • +
  • -

#3 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

Re: undefined index error?

Posted 14 May 2012 - 12:09 PM

this is a result
Fatal error: Can't use function return value in write context in C:\Program Files (x86)\EasyPHP-5.3.9\www\EIS\employee\subject-matrix-done.php on line 18
that mean it is not exist
how can defined the index to solve problem ?
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3515
  • View blog
  • Posts: 10,146
  • Joined: 08-June 10

Re: undefined index error?

Posted 14 May 2012 - 12:11 PM

then do not execute the code without submitting the form beforehand.
Was This Post Helpful? 0
  • +
  • -

#5 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

Re: undefined index error?

Posted 14 May 2012 - 12:13 PM

so , what can i do ?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1