简体   繁体   中英

PHP/MYSQL: formatting user input data as MYSQL timestamp to search mySQL table

I'm trying to create a page where a user can search the MySQL general_log between two date and times for all mySQL queries, but I don't know how to go about formatting the user input data so it can be read by the table.

Here's my (very) rough stab at it, I'm kind of lost; MYSQL query;

 $result = mysqli_query($con,"SELECT * FROM general_log WHERE event_time between UNIX_TIMESTAMP('$fromDate') AND UNIX_TIMESTAMP('$toDate'");

Form;

            <h1>Query Error Log</h1>    
        <h2>Insert Date/Time as format YYYY-MM-DD HH:MM:SS</h2>
        <h2>From Date:Time</h2><input type="number" id="fromDate" name="fromDate" value="" /> <p></p>
        <h2>To Date:Time</h2><input type="number" id="toDate" name="toDate" value="" /> <p></p>
        <p></p><input type="submit">

Thank you for any help

尝试这个

$result = mysqli_query($con,"SELECT * FROM general_log WHERE (event_time BETWEEN UNIX_TIMESTAMP('$fromDate') AND UNIX_TIMESTAMP('$toDate'))";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM