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 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决