form call

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
loongest
Forum Commoner
Posts: 25
Joined: Wed Apr 07, 2004 12:23 pm

form call

Post by loongest »

twigletmac | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

<?php


if(!checkdate($_POSTї'month'], 1 , $_POSTї'year']))
{
	$nowArray = getdate();
	$month = $nowArrayї'mon'];
	$year = $nowArrayї'year'];
}
else
{
	$month = $_POSTї'month'];
	$year = $_POSTї'year'];
}

$start = mktime(12,0,0,$month,1,$year);
$firstDayArray = getdate($start);

?>

<html>
<head>
<title>
<?php print "Calendar:" .$firstDayArrayї'month']. "  ".$firstDayArrayї'year'] ?> </title>
</head>

<body>
<form method="post" action="<?php print "$_SERVERїPHP_SELF]"; ?>">
<select name="month">

<?php
$months = Array("January","February","March","April","May","June","July","August","September","October","November","December");

for($x=1; $x<=count($months); $x++)
{
	print "\t<option value="$x"";
	print ($x == $month)?" SELECTED":"";
	print ">".$monthsї$x-1]."\n";
}

?>

</select>
<select name="year">
<?php

for($x=1980; $x<=2010;$x++)
{
	print "\t<option";
	print ($x == $year)?" SELECTED":"";
	print ">$x\n";
}
?>
</select>
<input type = "submit" value="GO!">
</form>
</body>
</html>



Notice: Undefined index: month in C:\Mywork\calendar\calendar.php on line 4

Notice: Undefined index: year in C:\Mywork\calendar\calendar.php on line 4




Sorry about that, i just need some1 can explain to me. i realise that the browser produce the 2 notice to me about the undefined index. May i knw the program having error when it suppose to call back from oringinal form, PHP_SELF or i just need to change the php.ini to
error_reporting = E_ALL & ~E_NOTICE this mode.? :roll:
If the program having error to call from the form, how do i modify ?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Please use

Code: Select all

tags not
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You need to check to make sure that $_POST variables are set before you try and use them, instead of:

Code: Select all

if(!checkdate($_POST['month'], 1 , $_POST['year']))
{
    $nowArray = getdate();
    $month = $nowArray['mon'];
    $year = $nowArray['year'];
}
else
{
    $month = $_POST['month'];
    $year = $_POST['year'];
}
try:

Code: Select all

$month = (isset($_POST['month'])) ? $_POST['month'] : date('m');
$year  = (isset($_POST['year'])) ? $_POST['year'] : date('Y');

if (!checkdate($month, 1, $year)) {
    $month = date('m');
    $year  = date('Y');
}
Note also that things like:

Code: Select all

<?php print "$_SERVER[PHP_SELF]"; ?>">
where you have a variable by itself inside double quotes should be:

Code: Select all

<?php print $_SERVER['PHP_SELF']; ?>">
Mac
Post Reply