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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器