dongtan3306 2016-11-19 09:07
浏览 94

将数据从HTML页面发送到PHP脚本并在PHP中选择数据

My HTML page

<html>
<body>
<form action="myScript.php" method="POST">
    Enter a transceiver ID:
    <br><br>
    <input type="text" name="id" >
    <br><br>
    <input type="submit" value="Submit">
</form>
</body>

My PHP script which is running on my server

<?php
$id_array = array("101");
while(1)
{
    if (isset($_POST['id']))
    { 
        $id = $_POST['id'];
        echo ("ID is ".$id."
");
        array_push($transceiverID_array, $id);
    }
    print_r($id_array);
    usleep(5000000);
    // lot of processing will be done 
}
?>

My PHP script is in a forever while loop. If I post some data from my HTML page, my PHP script is doing something else (which takes quite a lot of time), and not necessarily processing the line where it is checking if the variable from HTML page is set. So, even if I posted something from my HTML page, due to the long duration between posting data and the PHP script going on the isset line, my PHP script is unable to pick up data.

Is there any time limit in which I need to pick up the variable in my PHP script posted from the HTML page? Is there any better way of doing this?

Also, after posting, my HTML page, keeps waiting for my PHP script to respond. Is there any way to stop loading my HTML page?

  • 写回答

4条回答 默认 最新

  • douyou2368 2016-11-19 09:14
    关注

    As the other commentors asked. What is the point of having an infinite loop? The server will do the task of listen for requests in your behalf!

    It is natural that the HTML page doesn't receive anything, as the flow in your PHP script never ends. Remove that loop and try the request.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?