Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6854339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:37:17+00:00 2026-05-27T01:37:17+00:00

I am having trouble putting together a script that lists various business contact information.

  • 0

I am having trouble putting together a script that lists various business contact information.

Basically, the a user can either enter a business name, or choose from a set or categories, then click on the submit button, which then begins the search for results stored in a mysql database. This part works fine, as in a user can enter a name or choose a category, then click the button to see a table listing matching results. These results are paged in sets of 6.

Here is the code for the layout of the form:

$pageContent = '
    <div class="content">
    <h1>Browse Listings</h1>
    <div class="searchBox">
    <form method="post" action="'.$_SERVER['PHP_SELF'].'" name="search">
        Enter a Business Name: <input name="bizName" type="text" size="25" placeholder="Search..." />
        or Select a Category:   <select name="bizCategory">
                                <option>Choose</option>
                                <option>Accomodation</option>
                                <option>Retail</option>
                            </select>
        <button type="submit" name="searching" class="search" value="Search">Search</button>
    <!-- end .searchBox --></div>
    <br />
';

Here is the code that deals with the instance of a user clicking on Search when they have entered a name:

if ((isset($_POST['searching']) && $_POST['searching'] == "Search") || isset($_SESSION['bizFind']))
{
    if ((isset($_POST['bizName']) && $_POST['bizName'] == "") && $_POST['bizCategory'] == "Choose")
    { 
        $pageContent .= '
        <p>You forgot to enter a business name, or select a search category.</p>
        ';
    } else {

        ...

        if (((isset($_POST['bizName']) && $_POST['bizName'] !== "") && $_POST['bizCategory'] == "Choose") || (isset($_SESSION['bizFind']) && !in_array($_SESSION['bizFind'], array("", "Accomodation", "Retail"))))
        {

        if ((isset($_SESSION['bizFind']) && !in_array($_SESSION['bizFind'], array("", "Accomodation", "Retail"))) && !isset($bizFind))
        {
            $bizFind = $_SESSION['bizFind'];
        }
        else
        {
            $bizFind = $_POST['bizName'];
        }

With the emphasis on this line, being the actual instance:

    if (((isset($_POST['bizName']) && $_POST['bizName'] !== "") && $_POST['bizCategory'] == "Choose") || (isset($_SESSION['bizFind']) && !in_array($_SESSION['bizFind'], array("", "Accomodation", "Retail"))))

Now when a user navigates away from a page, and navigates back, the search value is held and the results are displayed.

But I cannot for some reason grasp the statement behind a user clicking Search, after selecting a category.

I have tried this:

    if ((isset($_POST['bizCategory']) && $_POST['bizCategory'] !== "Choose") || (isset($_SESSION['bizFind']) && ($_SESSION['bizFind'] == "Accomodation" || $_SESSION['bizFind'] == "Retail"))
    {
        if ((isset($_SESSION['bizFind'])  && ($_SESSION['bizFind'] == "Accomodation" || $_SESSION['bizFind'] == "Retail")) && !isset($bizFind))
        {
            $bizFind = $_SESSION['bizFind'];
        }
        else 
        {
            $bizFind = $_POST['bizCategory'];
        }

Which will trigger if a category is selected and a user hits Search, but will not trigger if the session variable has been set and a user navigates back to the listing area.

This causes a problem too with the paging, when a search category has been selected.

If the business name is used, the paging works fine, but when a category is selected, and a user tries to navigate to the next page of results, no data is returned as the variable $bizFind (search string) has not been set, or holds no value.

If anyone has any input, or suggestions for me, with this… It would be greatly appreciated.

But the question is what am i doing wrong with the second instance, that the script is not being trigged by the existance of the session variable (search string) alone.

Thank You!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:37:18+00:00Added an answer on May 27, 2026 at 1:37 am

    Phew, there’s a lot to wade through there! I would say to start with, simplify your calls. You can do this in two ways – firstly write a function that does the isset-and-retrieve:

    function getPost($v)
    {
        return isset($_POST[$v]) ? $_POST[$v] : null;
    }
    

    You can then swap this:

    if (isset($_POST['bizCategory']) && ($_POST['bizCategory'] !== "Choose")) ...
    

    with this:

    $bizCat = getPost('bizCategory');
    if ($bizCat && ($bizCat != 'Choose')) ...
    

    Also, given that you have quite complex bracketed expressions, do something like this:

    // Just a random example!
    $bizFindSession = (bool) getSession('bizFind');
    $bizCatPosted = ...
    if (!bizFindSession && $bizCatPosted) ...
    

    You’ll find your statements then will (a) have less brackets, and (b) will be easier to understand. If you use plain and readable English for your variable names, even better (since if statements can then be read almost like an English sentence).

    Lastly, don’t forget to do print_r($_POST); exit(); at strategic points from time to time – you can peek into where your app is going wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am putting together my first NSIS installer script, and having some trouble. I
I have this Caliburn.Micro sample project I'm putting together and I am having trouble
I am having some trouble putting a query together. I need to show images
I am putting together a website in codeIgniter, but I'm having some trouble with
I'm new to psuedocode, and I'm having trouble putting all the pieces together: Here
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
I was having trouble with the following macro, and I found out that the
I am trying to do something like this but am having trouble putting it
I'm having trouble computing a SHA1 hash from a string and then putting it
I am having great trouble trying to use mysql_fetch_assoc and mysql_result together in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.