douyin4875 2013-12-11 10:30
浏览 83
已采纳

单击按钮时用户输入的POST查询

This is what I'm trying to do. I let the user to input DATEFROM and DATETO. Then when the user click the button, it will execute a query to SELECT * from my table WHERE DATEFROM BETWEEN DATETO. I don't know what's wrong. Please help.

<html>
    <head></head>
    <body>
        <?php
        <form method="POST" action="">
        DATE FROM: <input type="date" name="datefrom"> TO: <input type="date" name="dateto"> <input type="submit" value="Extract excel file" name="extract"></input>
        </form>

        $datefrom = "datefrom";
        $dateto = "dateto";

        if(isset($_POST['extract'])){
            mysql_connect("localhost", "root");
            mysql_select_db("sample");

            $myquery = "SELECT * FROM biometrics WHERE date_created BETWEEN '" . $datefrom . "' AND '" . $dateto . "ORDER BY id_biometrics";


            $result = mysql_query($myquery);

            echo "<table border='1'>
            <tr>
                <th>ID</th>
                <th>Employee Number</th>
                <th>Date Created</th>
                <th>Time Created</th>
                <th>Status</th>
            </tr>";

            while($data = mysql_fetch_row($result))
            {
                echo("<tr>
                <td>$data[0]</td>
                <td>$data[1]</td>
                <td>$data[2]</td>
                <td>$data[3]</td>
                <td>$data[4]</td>
                </tr>");
            }

            echo "</table>";

        }

        ?>
    </body>
</html>
  • 写回答

4条回答 默认 最新

  • duanpu1111 2013-12-11 10:37
    关注

    you have missed a quote(') in query ,try like this

    if(isset($_POST['extract'])){
            mysql_connect("localhost", "root");
            mysql_select_db("sample");
    
              $datefrom = $_POST['datefrom'];
              $dateto = $_POST['dateto'];
    
            $myquery = "SELECT * FROM biometrics WHERE date_created BETWEEN '" . $datefrom . "' AND '" . $dateto . "' ORDER BY id_biometrics";
    
    
            $result = mysql_query($myquery);
    

    hope this works for you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 如何用数码管显示学号(相关搜索:单片机)
  • ¥15 错误于library(org.Hs.eg.db): 不存在叫‘org.Hs.eg.db’这个名称的程序包,如何解决?
  • ¥60 求一个图片处理程序,要求将图像大小跟现实生活中的大小按比例联系起来的
  • ¥50 求一位精通京东相关开发的专家
  • ¥100 求懂行的大ge给小di解答下!
  • ¥15 pcl运行在qt msvc2019环境运行效率低于visual studio 2019
  • ¥15 MAUI,Zxing扫码,华为手机没反应。可提高悬赏
  • ¥15 python运行报错 ModuleNotFoundError: No module named 'torch'
  • ¥100 华为手机私有App后台保活
  • ¥15 sqlserver中加密的密码字段查询问题