sabo86 Posted September 14, 2008 Share Posted September 14, 2008 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 More sharing options...
JasonLewis Posted September 14, 2008 Share Posted September 14, 2008 $query is not being set at all. With this if: if($_POST['searchtype']=='Seatings') Add a normal else at the end. }else{ $field = ""; } That way you are defining $field to be blank. Link to comment https://forums.phpfreaks.com/topic/124160-getting-right-results-with-an-error/#findComment-641035 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 I didn't get your point? would you plz explain? Link to comment https://forums.phpfreaks.com/topic/124160-getting-right-results-with-an-error/#findComment-641049 Share on other sites More sharing options...
JasonLewis Posted September 14, 2008 Share Posted September 14, 2008 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 } Link to comment https://forums.phpfreaks.com/topic/124160-getting-right-results-with-an-error/#findComment-641052 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.