php基于onclick功能的输入类型日期 [英] php the onclick function based input type date

查看:82
本文介绍了php基于onclick功能的输入类型日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户选择日期,月份和年份,然后按一个按钮,根据他选择的日期
向他显示数据库的值我不知道代码中的哪个问题

User chooses the date , month and year and then press a button to show him the value of database based on the day he picked I do not know where is the problem in the code

<style>
.button {border-radius: 8px;} 
.button1 {font-size: 20px;}
</style>
<form>

 إختر التاريخ : <input type="date" name="bday" id="dat"><br>

    <button type=button class="button button1" onclick="document.getElementById('data').innerHTML = myFunction(document.getElementById('dat').value)">إظهار الإستهلاك اليومي</button>
<hr>
<span id="data" ></span> 
</form>

<script>// <![CDATA[
    function myFunction($x) {
       $current_user=get_current_user_id();// to fetch the right data for the right user

  // ياخذ اليوم والشهر والسنه الي اختارها اليوزر
global $wpdb;
$d=date('j');//define variable to store the day
$m=date('m');//define variable to store the month
$y=date('Y');//define variable to store the year
$daily_amount= $wpdb->get_var("SELECT daily_amount FROM arduino_period_use where ID=$current_user and day=d and month=$m and year=$y ");
//print_r($daily_amount); 
        }

// ]]></script


推荐答案

也许如果你有一些错误检查,你会被告知你的SQL语法错误:

Perhaps if you had some error checking, you'd get told about your SQL syntax errors:

$daily_amount= $wpdb->get_var("[..snip..] and day=d and month=$m and year=$y ");
                                                  ^---- missing $

你不太可能有一个 d 字段,因此查询将失败,未知字段错误。

You're unlikely to have a d field in your DB, so the query will failed with unknown field errors.

这篇关于php基于onclick功能的输入类型日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆