How to set $_GET variable

前端 未结 9 458
梦如初夏
梦如初夏 2020-12-03 21:22

How do i set the variable that the $_GET function will be able to use, w/o submitting a form with action = GET?

相关标签:
9条回答
  • 2020-12-03 21:54

    You can create a link , having get variable in href.

    <a href="www.site.com/hello?getVar=value" >...</a>
    
    0 讨论(0)
  • 2020-12-03 21:54

    You can use GET variables in the action parameter of your form element. Example:

    <form method="post" action="script.php?foo=bar">
        <input name="quu" ... />
        ...
    </form>
    

    This will give you foo as a GET variable and quu as a POST variable.

    0 讨论(0)
  • 2020-12-03 21:58

    I know this is an old thread, but I wanted to post my 2 cents...

    Using Javascript you can achieve this without using $_POST, and thus avoid reloading the page..

    <script>
    function ButtonPressed()
    {
    window.location='index.php?view=next'; //this will set $_GET['view']='next'
    }
    </script>
    
    <button type='button' onClick='ButtonPressed()'>Click me!</button>
    
    <?PHP
     if(isset($_GET['next']))
        {
              echo "This will display after pressing the 'Click Me' button!";
        }
     ?>
    
    0 讨论(0)
提交回复
热议问题