Page 1 of 1

PHP Errors

Posted: Mon Aug 08, 2005 10:58 am
by quadoc
I've the following codes, it keep giving error - Notice: Undefined index: order in c:\Inetpub\wwwroot\schoolProject\admin\show.php on line 179. Can someone tells me why? Thanks...

Code: Select all

/******************* collect sort order (ASC/ DESC)*********************/

	$i_order = $_GET["order"];[/b]
		if($i_order == "")
		{
			$i_order = $_POST["order"];
		}
		/////////////
		if($i_order == "")
		{
			$i_order = 1;
			$s_sortorder = " DESC ";
		}
		else if($i_order ==  1)
		{
			$i_order = 0;
			$s_sortorder = " DESC ";
		}
		else if($i_order ==  0)
		{
			$i_order = 1;
			$s_sortorder = " ASC ";
		}

		//$i_col = $_GET["col"];


			/************** collect coloumn  no*******************/

		$i_col = $_GET["col"];
		if($i_col == "")
		{
			$i_col = $_POST["col"];
		}
		if($i_col == "")
		{
			$i_col = 3;
		}
		/*********************Switch case statement******************/


		switch($i_col)
		{
			case 0 :
				$s_sort = " order by pir ".$s_sortorder;
				break;
			case 1 :
				$s_sort = " order by email ".$s_sortorder;
				break;
			case 2 :
				$s_sort = " order by categories ".$s_sortorder;
				break;
			case 3 :
				$s_sort = " order by date_request ".$s_sortorder;
				break;	
			case 4 :
				$s_sort = " order by ID ".$s_sortorder;
				break;
			case 5 :
				$s_sort_assgn = 1;
				break;
			case 6 :
				$s_sort = " order by open ".$s_sortorder;
				break;	
		}

  ?>
  <input type=  "hidden" name = "order" value = "<?=$i_order?>">
  <input type=  "hidden" name = "col" value = "<?=$i_col?>">

Posted: Mon Aug 08, 2005 11:04 am
by Grim...
Um - what's on line 179 of show.php ?

Posted: Mon Aug 08, 2005 11:07 am
by quadoc
sorry, line 179 is the first line. For some reasons, there are two posts for this subject, I don't know why. But here is the link to the other post.

viewtopic.php?t=36620

Thanks...

Posted: Mon Aug 08, 2005 11:15 am
by Grim...
Line 179 is a comment?

Posted: Mon Aug 08, 2005 11:16 am
by Grim...
Point one:

Code: Select all

if ($value == "")
should really be

Code: Select all

if (!$value)

Re: PHP Errors

Posted: Mon Aug 08, 2005 11:27 am
by nielsene
When pulling in optional fields from GET or POST you should first check if the field is set. If you do this you'll avoid the NOTICE's you're getting.

Code: Select all

$i_order = isset($_GET["order"]) ? $_GET["order"] : 
                     isset($_POST["order"]) ? $_POST["order"] : 1;

Posted: Mon Aug 08, 2005 1:02 pm
by quadoc
Thank you nielsene for the tips...

Posted: Mon Aug 08, 2005 1:29 pm
by m3mn0n
Because it says an error happened on that line, doesn't necessarily mean the problem in your code is on that line.

It just happens to be where the PHP parser ran an error. And it's telling you where the error occured, not where the problem in your source is.

I'd look at 178 and everything above. And not to mention include()'d & require()'d files.


And to give you another tip, undefined index usually means you got registerglobals off and you didn't add something like the following to te top of your code...

Code: Select all

isset ($_POST['var'])
{
   $var = trim ($_POST['var']);
}

Posted: Fri Aug 12, 2005 8:01 am
by quadoc
Thanks for the Tips guys... :D