如何在PHP中使用URL中的值

时间:2016-03-03 05:19:12

标签: php html

我目前正在制作一个包含4个字段的报告错误表单:

  1. 工作ID $jobid
  2. 部件ID part_id
  3. 注意
  4. 用户点击与其工作相对应的表格,并将其带到具有变量的网址的新页面。目前所有字段都是空的,但我希望自动填充字段,除了笔记。

    当前模型

    链接到报告错误表单:

    $EM_html = '<a href="/report_error_form.php?JobID='.$jobid.'&Machine=EM&PartID='.$part_id.'">'.$tick.'</a>
    

    报告错误表单:

    <form action="" method="post">
            Job Number: <input type="text" value="<?php print ($jobid) ?>" name="jobNum"><br>
            Part Number: <input type="text" value="<?php print ($part_id) ?>" name="partNum"><br>
            Machine Code: <input type="text" name="machCode"><br>
            Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
            <input type="submit" name="submit" value="Submit">
    </form>
    

    示例网址

    http://sra-pstest/report_error_form.php?JobID=KANBAN16-09-04-01&Machine=EM&PartID=124047 如何从网址(JobID,Machine,PartID)中“提取”信息并自动填写表单?

5 个答案:

答案 0 :(得分:1)

您可以使用$_GET

import {Cmomponent, OnInit} from 'angular2/core';
import {ExternalService} from '../externalService';

export class app implements OnInit{
   constructor(myService:ExternalService)
   {
           this.myService=myService;
   }

   ngOnInit(){
     // this.myService.someMethod() 
   }
}

答案 1 :(得分:0)

请试试这个

<?php
        $jobid    = @$_REQUEST['JobID'];
        $part_id  = @$_REQUEST['PartID'];
        $machCode = @$_REQUEST['Machine'];
 ?>


    <form action="" method="post">
                Job Number: <input type="text" value="<?php print ($jobid) ?>" name="jobNum"><br>
                Part Number: <input type="text" value="<?php print ($part_id) ?>" name="partNum"><br>
                Machine Code: <input type="text" name="machCode"><br>
                Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
                <input type="submit" name="submit" value="Submit">
    </form>

答案 2 :(得分:0)

您使用$_GET方法,例如此代码

<?php 
$jobid=$part_id=$machine="";
if(isset($_GET['JobID']))
{
    $jobid= $_GET['JobID'];

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

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

}

&GT;

答案 3 :(得分:0)

 <form action="" method="post">
    <?php $jobNumber = isset($_GET['JobID']) ? $_GET['JobID'] : '' ?>
    Job Number: <input type="text" value="<?php echo jobNumber; ?>" name="jobNum"><br>
    <input type="submit" name="submit" value="Submit">
</form>

答案 4 :(得分:0)

尝试使用isset和post方法检查是否声明了变量,并在提交表单

时获取变量数据
<?php
    if(isset($_POST['submit'])){
      $jobid = $_POST['JobID'];
      $part_id = $_POST['PartID'];
      $machCode = $_POST['Machine'];
    }

&GT;

<form action="" method="post">
     Job Number: <input type="text" value="<?php echo $jobid; ?>" name="jobNum"><br>
     Part Number: <input type="text" value="<?php echo $part_id; ?>" name="partNum"><br>
     Machine Code: <input type="text" name="machCode" value="<?php echo $machCode; ?>"><br>
     Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
     <input type="submit" name="submit" value="Submit">
</form>


Hope this help