michaelk46 Posted October 29, 2009 Share Posted October 29, 2009 I am getting an error... It seems like the script is completely ignoring IF statements... When I hit submit on the search page, I get "SELECT * FROM pages WHERE searchid = and pagename = " in $sql Now if there are terms in one or both search fields, it enters the data into the correct part of the string, but it should only add "pagename =" if the pagename search field has search terms in it and "searchid =" should only come up when search terms are in Search ID field when the submit button is hit and 'and' should only come up if both search fields are populated. If there is nothing in either it should have "You must enter search terms" in $sql but I am getting the above string instead. I am not sure why...something tells me, I am missing something very small. Please help... if ($_SERVER['REQUEST_METHOD'] != "POST") { include "search.html.php"; } else { if(isset($_POST['searchid']) || (isset($_POST['pagename']))) { $sql = "SELECT * FROM pages WHERE "; if(isset($_POST['searchid'])) { $sql .= "searchid = ".$_POST['searchid'].""; } if(isset($_POST['searchid']) && (isset($_POST['pagename']))) { $sql .= " and "; } if(isset($_POST['pagename'])) { $sql .= "pagename = ".$_POST['pagename']." "; } } else{ $sql .= "You must enter search terms"; } include "searchres.html.php"; } Quote Link to comment https://forums.phpfreaks.com/topic/179555-solved-ignoring-if-statemanets/ Share on other sites More sharing options...
MadTechie Posted October 29, 2009 Share Posted October 29, 2009 Okay when you post from a form.. even is the value of a field is empty the field is still set so it ISSET change the ISSET's to !empty (not empty) so if(isset($_POST['searchid']) || (isset($_POST['pagename']))) becomes if(!empty($_POST['searchid']) || (!empty($_POST['pagename']))) Quote Link to comment https://forums.phpfreaks.com/topic/179555-solved-ignoring-if-statemanets/#findComment-947482 Share on other sites More sharing options...
michaelk46 Posted October 29, 2009 Author Share Posted October 29, 2009 Again, Thank You very much... This problem and the one you helped me with before have been baffling me for a while... I knew this had to be something small... Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/179555-solved-ignoring-if-statemanets/#findComment-947488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.