0

I am wanting to use one page that is linked to from two different pages. Below are my scenarios:

1) The user clicks a hyperlink to be directed to the page with a salesID in the URL
2) The user navigates directly to the page and no salesID is passed in the URL

Now to account for each situation above ->

1) If salesID IS NULL then get parameters from the page
2) If salesID IS NOT NULL then onload() display all relevant data for the salesID passed

I know how to write the query to load the page by default with a parameter, and I know how to load the page with parameters captured on the page from a button press event. What I do not know how to do is to combine the two and check multiple criteria. What I want to do is on pageload() evaluate criteria 1 - if a salesID is passed to the page, then go ahead and populate the page with all data for that salesID. If criteria 2 is true, then do not populate the page, wait for user input to select from select boxes and push the button.

This is basics of how I have the syntax for the page:

<?php
    //Capture variable from URL
    $salesID = urldecode($_GET['salesID']);

    //Check if variable is set
    if (isset($_GET['salesID'])) {
        //A salesID was passed to the page so load that data by default
        //ignoring any variables set on the page
    }
    else {
        if (isset($_POST['btnpressevent'])) {
            //button has been pressed capture variables from page and run query
        }
    }
?>
1
  • Out of curiousity, why don't you just populate the form with PHP then? Commented Sep 18, 2017 at 18:19

2 Answers 2

1

You could try this:-

    // if salesId is not set or is null then show form with select and button

 if (!isset($_GET['salesId']) || is_null($_GET['salesId'])) {
      $html = "<form action='samepage.php'><select><option>Select one</option><option>Item 1</option></select><button name='btnpressevent'>Press button</button></form>";
      echo $html;
      return; // or die();
    }

    // do stuff with salesId
    echo "${$_GET['salesId']} helllo w";
Sign up to request clarification or add additional context in comments.

1 Comment

Please read about what isset() checks for. Your condition is too verbose.
0

You should change $salesID = urldecode($_GET['salesID']); to $salesID = to_utf8($_GET['salesID']);

and then simply if(isset($salesID) {}

GET is already decoded and you've already declared it as a variable.

I'm not sure exactly what you're asking beyond it generally not working, but those two changes should help it work as intended.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.