0
<html>
<head>
<h1>Welcome</h1>
<h2>back</h2>

<form action='get.php' method='GET'>
Name: <input type='text' name='fname' /><br>
Age: <input type='text' name='age' />
<input type='submit' value ='clik here' />
</form>		

</head>		
</html>

<?php

$fname = $_GET['fname'];

$age = $_GET['age'];

if ($fname && $age)
 echo "your name is. $fname  , and your age $age <br>";
 

echo date ("m/y/d");
echo "<br>";



$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);



?>

the code above works , but i have no idea how come theres still an error message after. though i already declared the $fname and $age.

Notice: Undefined index: fname in C:\xampp\htdocs\xampp\get.php on line 17

Notice: Undefined index: age in C:\xampp\htdocs\xampp\get.php on line 19
04/11/20
Tomorrow is 2011/04/21

thanks :)

Edited by backalley: n/a

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by tomato.pgn
0

let's say your page is named test.php. When you first load http://yoursite.com/test.php
NOTHING has been "submitted", so $_GET['fname'] does not exist yet. You need to first check to see if it has been submitted.

<html>
<head>
<h1>Welcome</h1>
<h2>back</h2>

<form action='get.php' method='GET'>
Name: <input type='text' name='fname' /><br>
Age: <input type='text' name='age' />
<input type='submit' name="Submit" value ='clik here' />
</form>		

</head>		
</html>

<?php

if( isset($_GET['Submit']) && !empty($_GET['Submit']) )
{
  $fname = isset($_GET['fname']) ? $_GET['fname'] :'';

  $age = isset($_GET['age'])?$_GET['age']:'';

  if ($fname && $age)
   echo "your name is. $fname  , and your age $age <br>";
 

  echo date ("m/y/d");
  echo "<br>";



$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);

}

?>
0

$_GET,$_POST are methods that are initialised by values after a form is redirected or by assigning value to them manually.....
You are using them without checking if they have any value set or not so it is creating error..
To rectify your error....
just place your code between if statement and check whether it is set using isset() function...

if( isset($_GET['Submit']) && !empty($_GET['Submit']) )
This topic has been dead for over six months. 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.