Jump to content

help !! Undefined variable: option in on line 19


pidiw

Recommended Posts

<?php
include "config.php";

mysql_select_db($dbname);

         
   
      $result = mysql_query('select * from employee where status="accepted"');
      $sort="";
      
      if($_SESSION['user']==1){
      $option='edit';
      }
      elseif($_SESSION['user']==2){
      $option='approve/deny';
      }
   $count=mysql_num_rows($result);
   $statusList='accepted';
   tableLoop($count,$result,$option,$statusList);    line 19

function tableLoop ($count,$result,$option,$statusList){

   echo "<table id='table'>";
   if(empty($count)){
   echo "Empty Query";
   }
   else{
   echo"
      <tr bgcolor='#FFFF66' id='rowHead'>
      
      <th>Employee Number</th>
      <th>Last Name</th>
      <th>Middle Name</th>
      <th>First Name</th>
      <th>Position</th>
      <th>Age</th>";
         if(isset($_POST["company"])){
            echo "<th>Company</th>";
         }
      echo"</tr>";
   }
   $qualified = false;
   while($row = mysql_fetch_array($result)){
    if($qualified == true) {
      if ($row['status']=='bad'){
         $bgcolor="redRow";
         $dueCtr++;
        }
      elseif ($row['status']=='pending'){
         $bgcolor="yellowRow";
        }
      else{
         $bgcolor="neutralRow"; 
        }
      }    
     else{ 
      $bgcolor="neutralRow";
     }
     $company=$row['company']; 
     echo "<tr id='$bgcolor'>";
     $enable="onclick=form1.button3.disabled=false;form1.button1.disabled=false";
     echo "<td> <a href='viewrecord.php?docNumber=$row[0]&option=$option'>" . $row['empno'] . "</a></td>";
     $userResult=mysql_query("SELECT last name, middle name, first name, position, age  
                       from employee where company=('$company')") or die(mysql_error());
     $userRow=mysql_fetch_array($userResult);
     echo "<td> <a href='viewrecord.php?docNumber=$row[0]&option=$option'>" . $userRow['last name'] . "</a></td>";
     echo "<td> <a href='viewrecord.php?docNumber=$row[0]&option=$option'>" . $userRow['middle name'] . "</a></td>";
     echo "<td> <a href='viewrecord.php?docNumber=$row[0]&option=$option'>" . $userRow['first name'] . "</a></td>";
     echo "<td> <a href='viewrecord.php?docNumber=$row[0]&option=$option'>" . $userRow['position'] ."</a></td>";
     echo "<td><a href='viewrecord.php?docNumber=$row[0]&option=$option'>" . $userRow['age'] . "</a></td>";
     if($_SESSION["user"]==1){
     $docTypeResult=mysql_query("SELECT company from employee where company=".$row['company']."");
     $docTypeRow=mysql_fetch_array($docTypeResult);
     echo "<td> <a href='viewrecord.php?docNumber=$row[0]&option=$option'>" . $docTypeRow['company'] . "</a></td>";
     }
     echo "</tr>";
     }
     echo "</table>";

hello im kind of a newbie on php...anybody out there knows how to debug this??

 

MOD EDIT: code tags added.

hello im kind of a newbie on php...anybody out there knows how to debug this??

Debug that? Man, that code is a mess, and it's not even complete. Function tableLoop seems to have no closing }.

then you do things like:

 

$qualified = false;
...
if($qualified == true) {
      if ($row['status']=='bad'){

 

that is never going to run, because you manually set $qualified to false 1 line before you check it.

 

Also: always declare functions before you call them.

 

and this:

 

if($_SESSION['user']==1){
$option='edit';
}else if($_SESSION['user'] == 2){
$option='approve/deny';
}

 

what happens if $_SESSION['user'] is empty or does not exist ?

 

and this:

At the beginning you count the number of results, then you send all the variables into tableLoop... and in table loop you decide to check $count.

... but... even if $count is 0, you still try to do this: while($row = mysql_fetch_array($result))

 

very messy.

 

Try doing a little flowchart of what you want your code to do, so you can organize it in your head first.

  if($_SESSION['user']==1){
      $option='edit';
      }
      elseif($_SESSION['user']==2){
      $option='approve/deny';
      }

im assuming that neither of theses conditions are met, therefore you $options variable is never set

When posting code, enclose it within the forum's

 . . . 

BBCode tags.

 

There is no session_start] in that code. Is it in config.php? If yes, have you tried echoing $_SESSION['user'] to see what it's value is? If no, you can't use session variables without calling session_start().

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.