如何将表单变量传递给URL

问题描述:

I have a php page which is set to update an SQL record. This part works okay. The code has been written to redirect to page

watch_process.php?username='".$_POST['Username']."'

Which works fine and i can see the url has been amended correctly on the watch_process.php page when it loads. However, when I try to call it and print it on my php webpage, I get nothing.

<?php echo $_GET['username'] ?>

url looks like this: http://netfox-social.co.uk/watch_process.php?username=%27sysadmin%27&

我有一个设置为更新SQL记录的php页面。 这部分工作正常。 代码已编写为重定向到页面 p>

watch_process.php?username ='“。$ _ POST ['Username']。”' code> p>

哪个工作正常,我可以看到在加载时在watch_process.php页面上正确修改了网址。 但是,当我尝试调用它并在我的php网页上打印时,我什么都没得到。 p>

 &lt;?php echo $ _GET ['username']?&gt; \  n  code>  pre> 
 
 

url如下所示: http://netfox-social.co.uk/watch_process.php?username=%27sysadmin%27& p> div>

You could try $_REQUEST['username'] Request works for both, get and post. And I think the some of the quotes on the row watch_process.php?username='".$_POST['Username']."' are unneccessary

Answer by AirPett (See comments)

Have you any special intention in doing this?

     watch_process.php?username='". $_POST['Username']."'

Why not just do like so:

      // REMEMBER TO urlencode() THE $_POST['username'] VARIABLE
      $url = "watch_process.php?username=". urlencode($_POST['Username']);

     // AND THEN GET BACK YOUR QUERY STRING NORMALLY WITHOUT ANY TRIMMING LIKE SO:
     <?php echo $_GET['username']; ?>

     // AND IF YOU NEED SINGLE QUOTES AROUND THE $_GET['username'] VARIABLE 
     // YOU CAN EASILY ADD IT ONCE YOU'VE RETRIEVED IT LIKE SO:
     $username   = "'" . $_GET['username'] . "'";

But it is assumable that You most likely don't need the single-quotes except if you really otherwise do....