Jump to content

Getting right results with an error


sabo86

Recommended Posts

here is part of my code

if($_POST['searchtype']=='Seatings')
  $field='Seatings';

  elseif ($_POST['searchtype']=='Accessories')
  $field='Accessories';
  elseif ($_POST['searchtype']=="Local Office Furniture")
  $field='Local Office Furniture';
    elseif ($_POST['searchtype']=="European Office Furniture")
  $field='European Office Furniture';
   elseif ($_POST['searchtype']=="School and University Furniture")
  $field='School and University Furniture';

$query = "select * FROM items where Category = '$field' order by Model" ;
$query2="select * FROM items order by Model";

if ($_POST['searchtype']=='All')
{$result = mysql_query($query2)or trigger_error(mysql_error().'<br />Query was:'.$sql,E_USER_ERROR); ;}
else
  $result = mysql_query($query)or trigger_error(mysql_error().'<br />Query was:'.$sql,E_USER_ERROR); ;

  $num_results = mysql_num_rows($result);

  echo "<p>Number of records found: ".$num_results."</p>";

 

When I select "All" from the drop menu, I am getting the following result:

 

Notice: Undefined variable: field in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 53

 

Number of records found: 4

 

1.Model:Executive Office Arco

Description:Executive offices wooden frames anthracite lacquered; worktops, doors and drawer-fronts.

Category: European Office Furniture

Image:

 

2.Model:MOD. SERIE 2000

Description:Work Station

Category: Local Office Furniture

Image:

 

3.Model:MOD.098

Description:Anthropornetric desk

Category: School and University Furniture

Image: http://localhost/test%20fleifel/desk.JPG

 

4.Model:Operative Seatings T

Description:I love this descript

Category: Seatings

Image: http://localhost/test%20fleifel/desk.JPG

 

The results are right, but why is the NOTICE thing is displayed?

 

Link to comment
https://forums.phpfreaks.com/topic/124160-getting-right-results-with-an-error/
Share on other sites

Make this:

 

if($_POST['searchtype']=='Seatings')
  $field='Seatings';

  elseif ($_POST['searchtype']=='Accessories')
  $field='Accessories';
  elseif ($_POST['searchtype']=="Local Office Furniture")
  $field='Local Office Furniture';
    elseif ($_POST['searchtype']=="European Office Furniture")
  $field='European Office Furniture';
   elseif ($_POST['searchtype']=="School and University Furniture")
  $field='School and University Furniture';

 

This:

 

if($_POST['searchtype']=='Seatings'){
  $field='Seatings';

  }elseif ($_POST['searchtype']=='Accessories'){
  $field='Accessories';
  }elseif ($_POST['searchtype']=="Local Office Furniture"){
  $field='Local Office Furniture';
    }elseif ($_POST['searchtype']=="European Office Furniture"){
  $field='European Office Furniture';
   }elseif ($_POST['searchtype']=="School and University Furniture")
  $field='School and University Furniture';
}else{
$field = ""; //Set field to nothing
}

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.