|
 |
|
สอบถามเรื่องการเพิ่มปีครับ โดย เพิ่มปี หน้าและย้อนหลังได้ ครับ |
|
 |
|
|
 |
 |
|
คือว่าระบบนี้ครับ ผมอยากให้ เพิ่มปีงบประมาณได้ไม่เกิน 1 ปีครับ เช่น
ตอนนี้ ปี 2557 ก็เพิ่ม งบปี 2557 2558 ได้
แต่ถ้าเกิน 2558 ไปก็ยังเพิ่มไม่ได้เป็นต้นครับ
ผมลองใช้ if else เพื่อเช็คครับ แต่ว่า ยังไงๆมันก็บันทึกลงฐานข้อมูลได้ครับอะครับ
อันนี้เป็นหน้า budgetadd.php ครับ
Code (PHP)
<table width="904" height="162" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="" class="tb">
<thead class="tb">
<tr class="tb">
<th width="170" height="28" class="style2">ปีงบประมาณ</th>
<th width="734" align="left"><input name="txtbudget" type="text" required="required" id="txtname3" OnKeyPress="return chkNumber(this)" value="25" size="4" maxlength="4" minlength="3"/>
<span class="style2">(เช่น :25xx)</span></th>
</tr>
</thead>
<tr class="tb">
<td height="31" class="style2">จำนวนงบประมาณ</td>
<td><input name="txtmoney" type="text" required="required" id="txtname5" OnKeyPress="return chkNumber(this)"/>
บาท</td>
</tr>
</table>
หน้านี้เป็น budget_saveadd.php ครับ
Code (PHP)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require('connect.php');
?>
<?php
$txtbudget01 = $_POST['txtbudget'];
$date = date("Y") ;
$yearthai = $date+543 ;
$date01 = date("Y") ;
$yearthai01 = $date01+544 ;
$date02 = date("Y") ;
$yearthai02 = $date02+543 ;
?>
<?php
if($yearthai == $txtbudget01)
{
$txtbudget = $_POST['txtbudget'];
$txtmoney = $_POST['txtmoney'];
$sql ="insert into tbbudgetyear (
BudgetyearID,Budgetyear,Budgetyearmoney)values
('NULL','$txtbudget','$txtmoney')";
$result=mysql_query($sql,$conn);
echo "<script language='javascript'>alert('บันทึกข้อมูลเรียบร้อยแล้ว');</script>";
//echo "<meta http-equiv='refresh' content='0;url=selectlistbudget.php?year=$txtbudget' />";
}elseif($yearthai01 == $txtbudget01)
{
$txtbudget = $_POST['txtbudget'];
$txtmoney = $_POST['txtmoney'];
$sql ="insert into tbbudgetyear (
BudgetyearID,Budgetyear,Budgetyearmoney)values
('NULL','$txtbudget','$txtmoney')";
$result=mysql_query($sql,$conn);
echo "<script language='javascript'>alert('บันทึกข้อมูลเรียบร้อยแล้ว');</script>";
//echo "<meta http-equiv='refresh' content='0;url=selectlistbudget.php?year=$txtbudget' />";
}elseif($yearthai02 > $txtbudget01)
{
$txtbudget = $_POST['txtbudget'];
$txtmoney = $_POST['txtmoney'];
$sql ="insert into tbbudgetyear (
BudgetyearID,Budgetyear,Budgetyearmoney)values
('NULL','$txtbudget','$txtmoney')";
$result=mysql_query($sql,$conn);
echo "<script language='javascript'>alert('บันทึกข้อมูลเรียบร้อยแล้ว');</script>";
//echo "<meta http-equiv='refresh' content='0;url=selectlistbudget.php?year=$txtbudget' />";
}
else
{
echo "ปีงบประมาณนี้ผิดรูปแบบ" ;
}
?>
Tag : PHP, HTML/CSS, JavaScript, Ajax, jQuery

|
ประวัติการแก้ไข 2014-09-16 15:01:27 2014-09-16 15:03:07
|
 |
 |
 |
 |
Date :
2014-09-16 15:00:46 |
By :
nest12345 |
View :
704 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้ select list บังคับให้เค้าเลือกเลยครับ จัดการง่ายกว่านะผมว่า
Code (PHP)
<form id="form1" name="form1" method="post" action="">
<table width="904" height="162" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="" class="tb">
<thead class="tb">
<tr class="tb">
<th width="170" height="28" class="style2">ปีงบประมาณ</th>
<th width="734" align="left">
<select name="select" id="select">
<?PHP
$y = date('Y')+541;
for($i=1;$i<=3;$i++){
?>
<option value="<?PHP echo $y+$i; ?>"><?PHP echo $y+$i; ?></option>
<?PHP } ?>
</select></th>
</tr>
</thead>
<tr class="tb">
<td height="31" class="style2">จำนวนงบประมาณ</td>
<td><input name="txtmoney" type="text" required="required" id="txtname5" OnKeyPress="return chkNumber(this)"/>
บาท</td>
</tr>
</table>
</form>
|
ประวัติการแก้ไข 2014-09-16 16:08:53
 |
 |
 |
 |
Date :
2014-09-16 16:06:21 |
By :
arm8957 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เผื่อเจ้าของกระทู้จะกันอีกชั้นนะครับ
Code (PHP)
$txtbudget01 = $_POST['txtbudget'];
$year_now = date('Y');
$yearthai01 = $year_now + 544;
$yearthai02 = $year_now + 543;
if($txtbudget01 > yearthai01 || $txtbudget01 < $yearthai02 ){
echo 'ปีงบประมาณนี้ผิดรูปแบบ';
}else{
// บันทึกโลดดดดด
}
|
 |
 |
 |
 |
Date :
2014-09-16 18:25:36 |
By :
{Cyberman} |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|