php基于onclick函数的输入类型日期

php基于onclick函数的输入类型日期,php,date,Php,Date,用户选择日期、月份和年份,然后按下按钮,根据他选择的日期显示数据库的值 我不知道代码中的问题在哪里 <style> .button {border-radius: 8px;} .button1 {font-size: 20px;} </style> <form> إختر التاريخ : <input type="date" name="bday" id="dat"><br> <button type=butt

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

<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

.按钮{边界半径:8px;}
.button1{字体大小:20px;}
إ㶪㶪㶪㶪㶪㶪㶪:
إظهار الإستهلاك اليومي
//获取风险值(“从arduino_期间选择每日金额,其中ID=$current_user,day=d,month=$m,year=$y”); //打印金额(每日金额); }
//]]>如果您进行了一些错误检查,可能会被告知您的SQL语法错误:

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

数据库中不太可能有
d
字段,因此查询将因未知字段错误而失败。

问题是PHP是一种服务器端语言,其操作方式与javascript完全不同(完全不同),看起来您将两者混淆了


查看使用javascript与服务器端PHP代码通信以访问数据库记录的ajax请求

我认为您对PHP(服务器端脚本)和javascript(客户端脚本)非常困惑,也许可以在查询中研究一些PHP-js-ajax,
day=d
,应该是
day=$d
我修改了$d并再次尝试,但没有成功。然后,您需要解释此代码是如何工作的。我选择了日期,但当我单击按钮时,不会显示结果,而是使用
var\u dump($daily\u amount)
。如果get\u var失败或找不到任何内容,它将返回null,print\r将以空字符串(不可见)的形式转储。是否调用按钮true?我认为按钮上的问题我想问一个问题,当用户选择日期时,可以将日期存储为$d,月份存储为$m,年份存储为$y