9 Replies - 2323 Views - Last Post: 14 July 2009 - 02:08 AM Rate Topic: -----

#1 vasanth1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-July 09

how to calculate age in php?

Post icon  Posted 12 July 2009 - 11:11 PM

i have develop the form ,in this form i want to enter only age>18 what can i do
Is This A Good Question/Topic? 0
  • +

Replies To: how to calculate age in php?

#2 maffelu  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 40
  • View blog
  • Posts: 190
  • Joined: 21-August 08

Re: how to calculate age in php?

Posted 12 July 2009 - 11:34 PM

If you want to do it serverside you will have to check the form value.

If the input element for age is named "age" then you can check it like this:

if($_POST['age'] > 18){
   //you old enough
} else {
   //you're too young!
}


But if you want to make an "instant" check you will need to use javascript.
Was This Post Helpful? 0
  • +
  • -

#3 dreadfear  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 180
  • Joined: 08-December 08

Re: how to calculate age in php?

Posted 12 July 2009 - 11:34 PM

<body>
<form action= "age.php" method="post">
Age: <input type="text" name="age" />
<input name="Submit" type="submit" value="Login"/>
</form> </body>


<?php
$age = $_POST['age'];

if ($age > 18){
	header("Location: url");
}
else{
	header("Location: url");
}
?>


You havent even attempted this.

www.w3schools.com


They teach this on pretty much the first few tutorials they have, im not even going to tell you how any of it works or how to structure it.

You learn that yourself. You need to put in effort otherwise you get no where.
Was This Post Helpful? 0
  • +
  • -

#4 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: how to calculate age in php?

Posted 13 July 2009 - 09:42 AM

i'd make it
if( (int) $age > 18)


Was This Post Helpful? 0
  • +
  • -

#5 vasanth1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-July 09

Re: how to calculate age in php?

Post icon  Posted 14 July 2009 - 12:39 AM

Hi All,i have develop the form in this i want enter only age>18 with reference of bithday and how to calculate difference between two dates
Was This Post Helpful? 0
  • +
  • -

#6 paperclipmuffin  Icon User is offline

  • Disassembling...
  • member icon

Reputation: 13
  • View blog
  • Posts: 944
  • Joined: 16-April 09

Re: how to calculate age in php?

Posted 14 July 2009 - 12:44 AM

Hi and welcome to Dream.In.Code!

Here we have a policy which says we can't give you code until you show us the code you have used so far to tr to solve the problem. :)

Thanks for helping us help you.
Was This Post Helpful? 0
  • +
  • -

#7 vasanth1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-July 09

Re: how to calculate age in php?

Posted 14 July 2009 - 01:37 AM

View Postpaperclipmuffin, on 13 Jul, 2009 - 11:44 PM, said:

Hi and welcome to Dream.In.Code!

Here we have a policy which says we can't give you code until you show us the code you have used so far to tr to solve the problem. :)

Thanks for helping us help you.

Attached File(s)

  • Attached File  index.php (1.35K)
    Number of downloads: 37

Was This Post Helpful? 0
  • +
  • -

#8 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: how to calculate age in php?

Posted 14 July 2009 - 01:39 AM

Have a look here:
http://www.dreaminco.../snippet634.htm

and maybe here:
http://www.dreaminco...wtopic19953.htm

*edit* spelling

This post has been edited by firebolt: 14 July 2009 - 01:39 AM

Was This Post Helpful? 0
  • +
  • -

#9 vasanth1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 12-July 09

Re: how to calculate age in php?

Post icon  Posted 14 July 2009 - 01:46 AM

Hi All,i have develop the form in this i want enter only age>18 with reference of bithday and how to calculate difference between two dates

<?php

	include('config.inc');

	if (isset($_GET['message'])) {
		$message = $_GET['message'];
	}

	// Get the list of employees from database
	$sel_emp = "SELECT * FROM emp";
	$emp_rs = mysql_query($sel_emp) or die(mysql_error());
	$no_of_rows = mysql_num_rows($emp_rs);

	$data = array();

	while ($row = mysql_fetch_array($emp_rs, MYSQL_ASSOC)) {
		$data[] = $row;
	}

?>

 <head>
 <title>Welcome to Hello World</title>
</head>   
<body>

<?php
	if (isset($message)) {
		echo '<center>' . $message . '</center>';
	}
?>

	<h1>Employees List</h1>
	<hr color="#330066">

	<TABLE border="1" width="500">
		<TR bgcolor="#AEAEAE">
			<TH>Id</TH>
			<TH>Name</TH>
			<TH>Job</TH>
			<TH>DoB</TH>
			<TH>Actions</TH>
		</TR>

<?php
	
	if (count($data) > 0) {
	
		foreach ($data as $eachemp) {
?>
		<TR>
			<TD><?php echo $eachemp['id'];?></TD>
			<TD><?php echo $eachemp['name'];?></TD>
			<TD><?php echo $eachemp['job'];?></TD>
			<TD><?php echo $eachemp['dob'];?></TD>
			<TD><a href="edit.php?id=<?php echo $eachemp['id'];?>">edit</a> | <a href="delete.php?id=<?php echo $eachemp['id'];?>">Delete</a></TD>
		</TR>
<?php
		}
	}
	else {
?>
		<TR>
			<TD align="center" colspan="5"><font color=red>No Record Found</font></TD>
		</TR>
<?php
	}
?>
	</TABLE>

	<a href="insert.php">add new employee</a>

</body>
</html>



this is my code

** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5191
  • View blog
  • Posts: 26,903
  • Joined: 10-May 07

Re: how to calculate age in php?

Posted 14 July 2009 - 02:08 AM

** Topics Merged **

Please don't continuously open this same topic. Reply under this post. Thank you. :D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1