|
 |
|
php เรื่องของการเช็ค อายุ น้อยกว่า 15 ปี ไม่ให้ insert คับ (PHP Checking Age/Old) |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
function GetAge($DOB) {
list($Year, $Month, $Day) = explode("-",$DOB);
$YearDifference = date("Y") - $Year;
$MonthDifference = date("m") - $Month;
$DayDifference = date("d") - $day;
if ($DayDifference < 0 || $MonthDifference < 0) {
$YearDifference--;
}
return $YearDifference;
}
$year = 1995;
if(GetAge($year)<18)
{
echo "Too Young";
}
else echo "Old enough";
|
 |
 |
 |
 |
Date :
2010-10-06 14:56:34 |
By :
บุญรัด |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณ คับผม
|
 |
 |
 |
 |
Date :
2010-10-06 15:27:47 |
By :
mackyzaza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คือผม เขียน ไว้นะคับ แต่ไม่เช็คให้ นะคับ ช่วยหน่อยนะคับผม
Code (PHP)
include('../connect/connect_db.php');
$y=date("Y");
$emp_birthday=$_POST['emp_birthday'];
$CHECK=substr($emp_birthday,0,4);
$Old=($y)-($CHECK);
if($Old<=15){
echo "<script>
alert('คุณต้องมีอายุมากกว่า 15 ปี กรุณากรอกใหม่');
window.location='employee_from.php';
</script>";
exit();
}else{
echo "";
}
$emp_username=$_POST['emp_username'];
$emp_password=$_POST['emp_password'];
$emp_name=$_POST['emp_name'];
$emp_lastname=$_POST['emp_lastname'];
$emp_birthday=$_POST['emp_birthday'];
$emp_card=$_POST['emp_card'];
$emp_sex=$_POST['emp_sex'];
$emp_address=$_POST['emp_address'];
$emp_phone=$_POST['emp_phone'];
$stadmin=$_POST['stadmin'];
$active=$_POST['active'];
$emp_date=$_POST['emp_date'];
$emp_password=$_REQUEST['emp_password'];
$passen=base64_encode(base64_encode(base64_encode($emp_password)));//อันนี้เรียกว่า การเข้ารหัสนะพี่น้องโอ้ย
$SQL="SELECT MAX(emp_id) as num FROM employee_tb";
$rs=$db->Execute($SQL)or die('ERROR1');
$Result=$rs->fields;
$MaxID=$Result['num'];
if(empty($MaxID)){
$MaxID=1;
}else{
$MaxID=$MaxID+1;
}
$SQL1="INSERT INTO employee_tb (emp_id,emp_username,emp_password,emp_name,emp_lastname,emp_birthday, emp_card,emp_sex,emp_address,emp_phone,stadmin,active,emp_date)
VALUES($MaxID,'$emp_username','$passen','$emp_name','$emp_lastname', '$emp_birthday','$emp_card','$emp_sex','$emp_address','$emp_phone','$stadmin','active',curdate())";
$rs1=$db->Execute ($SQL1) or die ('ERROR1');
if($rs1){
echo"<script>
alert(\"บันทึกข้อมูลเรียบร้อย\");
window.location='employee_from.php';
</script>";
}else{
echo"<script>
alert(\"บันทึกข้อมูลไม่สำเร็จ\");
window.location='employee_from.php';</script>";
}
|
 |
 |
 |
 |
Date :
2010-10-06 15:32:13 |
By :
mackyzaza |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$emp_birthday=$_POST['emp_birthday'];
$CHECK=substr($emp_birthday,0,4);
$Old=($y)-($CHECK);
ลอง echo 3 ค่านี้ดู ว่าได้อะไรบ้าง
|
 |
 |
 |
 |
Date :
2010-10-07 20:24:32 |
By :
iieszz |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|