how to calculate age in php?
Page 1 of 19 Replies - 1657 Views - Last Post: 14 July 2009 - 02:08 AM
#1
how to calculate age in php?
Posted 12 July 2009 - 11:11 PM
Replies To: how to calculate age in php?
#2
Re: how to calculate age in php?
Posted 12 July 2009 - 11:34 PM
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.
#3
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.
#4
Re: how to calculate age in php?
Posted 13 July 2009 - 09:42 AM
if( (int) $age > 18)
#5
Re: how to calculate age in php?
Posted 14 July 2009 - 12:39 AM
#6
Re: how to calculate age in php?
Posted 14 July 2009 - 12:44 AM
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.
#7
Re: how to calculate age in php?
Posted 14 July 2009 - 01:37 AM
paperclipmuffin, on 13 Jul, 2009 - 11:44 PM, said:
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)
-
index.php (1.35K)
Number of downloads: 37
#8
Re: how to calculate age in php?
Posted 14 July 2009 - 01:39 AM
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
#9
Re: how to calculate age in php?
Posted 14 July 2009 - 01:46 AM
<?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 **
#10
Re: how to calculate age in php?
Posted 14 July 2009 - 02:08 AM
Please don't continuously open this same topic. Reply under this post. Thank you.
|
|

New Topic/Question
Reply




MultiQuote






|