dongtuan1980 2019-07-03 09:29
浏览 43

无法将输入时间格式转换为mysql识别的格式

I have a date input stored in a variable (no hour etc, just the date). I am trying to format it to then compare it to a date in MySQL database, but keep getting the Following error in reference to my PHP file…

"Notice: A non well formed numeric value encountered"

You'll see in my code below I've tried a couple of different methods of converting my date into a MySQL readable date, but to no avail.

I've been trying to do this conversion in the PHP file itself, is that right?

I haven't shown the connection code below as I know that works and may confuse things.

if (isset($_POST["date"])) {

    $date = $_POST["date"];
    $sqlDate = date("Y-m-d", $date);
    // $sqlDate = strftime('%Y-%m-%d',$date);
    $url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http") . "://$_SERVER[HTTP_HOST] $_SERVER[REQUEST_URI]";
    $id = basename($url);
    // echo $id;

    $stmt = $conn->prepare("SELECT * FROM planning WHERE intervenant = :id AND date = :sqlDate");
    $result = $stmt->execute([':id' => $id, ':sqlDate' => $sqlDate]);

    if ($stmt->rowCount() > 0) {
        $output = array();
        $output = $stmt->fetch(PDO::FETCH_ASSOC);
        echo json_encode($output);
    } else {
        $errors = "No data found for this date";
        echo json_encode($errors);
    }
    // $conn->close();
}

The aim is pretty self-explanatory, I'd like to be able to confirm my input date with a list of dates within a database, then pull matching rows out of the database to be shown/used client side…

Thank you for any help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计