- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,对于我的一项学校作业,在用户输入生日后,我一直无法向他们回显。我必须通过两种方式向用户回显。 1) 如果日期等于他们的生日,他们会收到一条不错的消息,2) 如果日期不等于他们的生日,那么他们会收到一条不同的消息。
由于某种原因,我的 if 语句不起作用...帮助?
这是 if 语句......
<?php
//if statement for birthday
$month = $_POST['month'];
$year = $_POST['year'];
$day = $_POST['day'];
$date = $year ."-". $month ."-".$day;
$date = date("Y-m-d",strtotime($date));
if(date('m-d') == date('m-d', $date)) {
// today is users birthday. show any message you want here.
echo "<p>Happy Birthday $firstname!</p>\n";
} else {
echo "<p>You were born $date.</p>\n";
}
?>
还有...这是下拉列表...
<?php
$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
//1950 is standard year thing for most websites I've noticed
$yearFrom = 1950; // The first year included in the drop-down for years
// $yearFrom = date("Y")-80;
// Using this line instead, gives a dynamic range of years, always 80 years
// Echo out all years via a for-loop
//<select> IS the dropdown box
echo "<select name=\"year\" id=\"year\">";
//less than or equal to current year
for ($yearFrom; $yearFrom <= date("Y"); $yearFrom++) {
// Each $yearFrom represents a year, always incremented by 1 year
//echos out every year that we put present.......
echo "<option value=\"$yearFrom\">$yearFrom</option>";
}
echo "</select>";
// Echo out all months from the array $months
echo "<select name=\"month\" id=\"month\">";
foreach($months as $key=>$value) {
// $key is the index of the array, starting at 0
$numericMonth = $key + 1;
echo "<option value=\"$numericMonth\">$value</option>";
}
echo "</select>";
// Echo out all days (1-31) via a for-loop
echo "<select name=\"day\" id=\"day\">";
for ($i=1; $i <= 31; $i++) {
// Each $i represents a numeric value of days, from 1-31
echo "<option value=\"$i\">$i</option>";
}
echo "</select>";
?>
所以...这就是我所拥有的..非常感谢所有想法和帮助。 :)
最佳答案
查看演示 here
要使用 strtotime()
并获得准确的结果,请首先设置您的日期和时区。
试试这个,
date_default_timezone_set ('Asia/Kolkata');// this leni should be added to use strtotime()
$date = "date from post value";
if (date('m-d', strtotime($date)) == date('m-d')) {
echo "<p>Happy Birthday $firstname!</p>\n";
} else {
echo "<p>You were born $date.</p>\n";
}
查看演示 here
关于php - 如果日期等于用户的生日,如何向用户回显?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33338054/
"); ..... 回显 (""); ?> 是什么意思?
问题是标签 我看过我正在编写的一个脚本,并使用了它: echo (""); ........ echo (""); 它到底做了什么? 它是 Html 标签还是 PHP? 我在 Google 上进行了
我正在创建一个结帐系统。我分为三个部分: 送货信息 付款信息 订单确认 我正在尝试找出一种方法,当客户输入他们的送货信息时,该数据可以回显到我的订单确认部分,这样他们就可以确认这是他们想要将其运送到的
我正在 MYSQL 表上运行 SELECT 代码 我有一个 MYSQL 表: CREATE TABLE mytable ( wf_id int(11) UNSIGNED NOT NULL, sessi
我想要做的是回显页面顶部的内容,同时捕捉页面底部的内容。 这是我的脚本: Westpop Wachtwoord moet minstens 8 tekens lang
我在将选择列表放在 HTML 中时遇到了一些困难,其中的选项或值是从数据库中的表中检索的。我得到以下结果: 如您所见,这不是我的本意,我宁愿将所有选项都放在 1 个选择列表中,并且可以单击多个选项。
我的代码有问题。我有这段代码: Title Welcome loggedin:
我需要使用 PHP 仅回显 .txt 文件中的选定行。txt 文件内容如下所示: 1 111 111 111 111 111 111 111 111 111 111 2 196 182 227 190
我需要使用 PHP 仅回显 .txt 文件中的选定行。txt 文件内容如下所示: 1 111 111 111 111 111 111 111 111 111 111 2 196 182 227 190
我想从 PHP 回显一些 HTML,其中包含一个链接,上面有文本“ ' '; 最佳答案 如果您想显示文字小于号,请根据 HTML 规范将其编码为 <。 您可能还想查看另一个相关实体:«。这会产生一个
如果我从名为 categories 的 mysql 表中调用链接列表,我想我使用的选择语句如下: $query = "SELECT cat_name, cat_description FROM c
所以,伙计们,我的问题是我正在从一个 mysql 列创建一个数组,但是,当我回显数组项时,它什么也没返回,我有一段时间没有看到一个可能的错误,希望能得到一些帮助。这是我的代码:(我知道 mysql 到
在下面的代码中,我在 php 文件中回显了 $strXML,它显示了整个 $strXML,但我只想在 javascript 中显示“名称”元素值。谁能帮帮我? PHP: $strXML = ''."\
我有一节课用这段代码 public boolean busybox() throws IOException { try { Process p =Ru
我有一个 SQL 查询,出于安全目的,我最近将其转换为准备好的语句。我有一个查询返回许多行,每行由许多列组成。我的问题是如何使用 while 循环回显结果。到目前为止我的例子: $stmt = $co
我尝试这样的事情: function userrank($userid){ $sql = mysql_query("SELECT * FROM users ORDER BY atacs DES
我正在尝试进行选择查询并将此信息输出到 html 标签中,但是它不断将 php 代码转换为: 我做错了什么?为什么它不返回错误而不是将其转换为上面的错误? 代码 $con = mysqli_conn
抱歉含糊其辞,但我有一个 PHP 脚本,它从数据库中提取数据并显示它,但是它不是输出数据库的内容,而是输出“数组”的次数。 (无法再次工作,脚本已上传 here ),脚本的输出也是 here .)谢谢
我有一个工作代码并将其移动到一个新服务器,从 php5 到 php7。谷歌搜索一周没有帮助我,所以我问你们。 我在 sql 数据库中有一些带有欧元符号的信息: 99.00该信息存储为 utf16-ge
这是我的代码: 0){ $info = mysql_fetch_assoc($result); while($row = mysql_fetch_assoc($result)){
我在查找有关此主题的信息时遇到了一些真正的困难,如果您有任何帮助,我将非常感激。简而言之,我有一个表单,用户可以从下拉列表中选择一个类别,输入一些内容,然后点击提交,然后转到 SQL。下拉列表中的每个
我是一名优秀的程序员,十分优秀!