Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.