0

I have this part of code

<?php 
$showmonth=$_POST['showmonth'];
$showyear=$_POST['showyear'];
$showmonth=preg_replace('#[^0-9]#i','',$showmonth);
$showyear=preg_replace('#[^0-9]#i','',$showyear);

$day_count=cal_days_in_month(CAL_GREGORIAN,$showmonth,$showyear);
$pre_days=date('w',mktime(0,0,0,$showmonth,1,$showyear));
$post_days=(6-(date('w',mktime(0,0,0,$showmonth,$day_count,$showyear))));

but i get errors like undefined index showyear,and errors on cal_days_in_month parameter 3 expected to be long, and also mktime parameter 6 expected to be long all due to the undefined index, how do i fix it?

2
Contributors
2
Replies
6
Views
4 Years
Discussion Span
Last Post by riahc3
0

My suggestion:

<?php 
$showmonth=(int)$_POST['showmonth'];
$showyear=(int)$_POST['showyear'];
$showmonth=preg_replace('#[^0-9]#i','',$showmonth);
$showyear=preg_replace('#[^0-9]#i','',$showyear);

$day_count=cal_days_in_month(CAL_GREGORIAN,$showmonth,$showyear);
$pre_days=date('w',mktime(0,0,0,$showmonth,1,$showyear));
$post_days=(6-(date('w',mktime(0,0,0,$showmonth,$day_count,$showyear))));

When you POST something, PHP thinks always it is a string. So you are mixing numbers with strings and that in any program language is always a bad idea.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.