dongyo1959 2017-09-18 18:15
浏览 65
已采纳

PHP检查是否设置了变量

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
        }
    }
?>
  • 写回答

2条回答 默认 最新

  • dsmnedc798226 2017-09-18 18:30
    关注

    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";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀