使用$ _GET ['']; $ _POST ['']内的值,并将其提交到同一页面并显示在同一页面中

时间:2018-01-01 01:23:39

标签: php html mysql forms

我是php的新手,而我正在实践中遇到了一个问题。实际上,我有两个文件index1.php和index2.php。在index1.php中,我有一个唯一ID为

的链接
loadSomeDataSync()

我在index2.php中得到了这个值为

<a href="index2.php?companyid=<?php echo $row('company_id');?>>details</a>

现在我在index2.php中有一个搜索表单

if(isset($_GET['companyid'])){
  $companyid = $_GET['companyid'];
 }

现在点击按钮我希望搜索结果显示在与

相同的页面中
<form method="POST" action="index2.php">
  <input type="text" name="search">
  <button type="submit" name="submit">submit</button>
</form>

但有些如果我尝试在同一页面中使用'index2.php?companyid=$companyid' ,它会将我带到index2.php而不是$_POST['submit'];,如果我不这样做,它会导致index2.php?companyid=$companyid错误39; t使用undefined index of $companyid$_POST['submit'];它会给出价值并且工作正常。我想要的只是使用echo $companyid;并将结果显示在与之前相同的网址

$companyid' value inside ``$_POST['submit'];

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

正如Josh在评论中指出的那样,PHP无法记住您之前的GET请求,但可以通过更改action元素的form属性轻松解决此问题。通过这样做,您可以传递以前的数据。这看起来有点像这样:

<form method="POST" action="index2.php?companyid=<?php echo $companyid;?>">
    <input type="text" name="search">
    <button type="submit" name="submit">submit</button>
</form>

通过这种方式,您将被重定向到index2.php并显示网址参数,您将能够使用search和{{1}检索companyid$_POST或者使用$_GET

答案 1 :(得分:0)

首先,您似乎没有在表单中使用公司ID,因此不会将其作为void Update() { Touch touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) // when screen is touched... { RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenToWorldPoint(touch.position), Vector3.forward, out hit)) // ...cast a ray... { if (hit.collider.tag == "sphere") //...and check if ray hits a sphere { selectedObject = hit.collider.gameObject; } } } // add touch controls here and apply to selectedObject for movement } 的一部分提交。您可以使用:

POST

但您可能还需要将逻辑更改为:

<form method="POST" action="index2.php">
  <?php if (isset($companyid)): ?>
    <input type="hidden" name="companyid" value="<?= $companyid; ?>">
  <?php endif; ?>
  <input type="text" name="search">
  <button type="submit" name="submit">submit</button>
</form>
相关问题