[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1948
  • Last Modified:

Why is this PHP script throwing errors?

Why it this PHP script throwing errors?

<select name="q2" id="q2" required>
<option value="">---- Select One ----</option>
<?php
	$start_year = date('Y')-100;
	$end_year   = $start_year+100;						
	for($i=$start_year; $i<=$end_year; $i++) {				
		if ($_SESSION['q2'] == $i.date()) {					
			echo '<option value='.$i.date().' selected="selected">'.$i.date().'</option>';
		} else {				
			echo '<option value='.$i.date().'>'.$i.date().'</option>';				   
	   }				   
	}
?>
</select>

Open in new window


When I view the underlying generated source code for this select dropdown,  I see the following error message for each iteration in the loop.  How can I modify my PHP script to eliminate it?

Warning:  date() expects at least 1 parameter, 0 given in /home/ideasdes/public_html/sts/index.html on line 1253

Thanks!
- Yvan
0
egoselfaxis
Asked:
egoselfaxis
  • 2
  • 2
1 Solution
 
Radek BaranowskiFull-stack Java DeveloperCommented:
This is not error, this is warning. Your program is probably working fine.
You can either specify date formattign string as described here: http://www.w3schools.com/php/func_date_date.asp

Or supress PHP warnings by using
error_reporting(1);
at the beginning of your php script.
0
 
GaryCommented:
I'm guessing, based on your code, where you have you date() you should be using
date('Y')
0
 
egoselfaxisAuthor Commented:
Right you are -- thank you very much!

- Yvan
0
 
Radek BaranowskiFull-stack Java DeveloperCommented:
nice one :) good luck.
0
 
GaryCommented:
Warnings are there for a reason, you don't just suppress them and pretend like they don't exists - the code is wrong and needs to be fixed
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now