dongyan4157 2015-06-09 11:25
浏览 246
已采纳

表单提交后重定向返回并回显结果

I have got this code on page1.php:

<form action="mcgen.php" id="form1" method="POST">
<input style="margin-right:-160px;" name="name1" type="text" id="form-field-1" placeholder="username:password" class="form-control" value="<?php echo $line ?>"> 
</div>
<button style="margin-right:-160px;" type="submit" name="gen" id="gen">Generate</button>

The mcgen.php file has this code:

<?php
if(isset($_POST['gen'])){                   
$f_contents = file("001.txt");
$line = $f_contents[array_rand($f_contents)];
$data = $line;

list($first, $last) = explode(':', $line);
}
?>

I am trying to make it so after they click the "Generate" button it will run the code in mcgen.php and then return to page1.php and echo "$line".

  • 写回答

3条回答 默认 最新

  • duanmorong9597 2015-06-09 11:30
    关注

    on mcgen.php

    header('Location: page1.php?line='.$line);
    

    on page1:

    if (isset($_GET['line'])) {echo $_GET['line'];}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

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