Jump to content

[SOLVED] ignoring IF statemanets


michaelk46

Recommended Posts

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";
}

Link to comment
https://forums.phpfreaks.com/topic/179555-solved-ignoring-if-statemanets/
Share on other sites

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'])))

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.