|
|
|
php สอบถามให้ขึ้นเตือนตอน add ข้อมูลเมื่อมีการเพิ่ม weight มากกว่า 100 คะแนน |
|
|
|
|
|
|
|
เเก้ไขได้ทั้งหมดแล้ว ลบ เพิ่มได้แล้ว ค้นหาโดยใช้listได้แล้ว
แต่ต้องการจะสอบถามให้ขึ้นเตือนตอนaddข้อมูลเมื่อมีการเพิ่มweightมากกว่า100คะแนนให้ขึ้นเตือนว่าคุณใส่คะแนนเกิน100คะแนน
Code (PHP)
<?
session_start();
include('config.php');
error_reporting(0);
if($_SESSION['rh_password'] != $rh_password){
echo "System not allowed access this page.";
die;
}
//Add Condition
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO cf_ass_category ";
$strSQL .="(cat_id,period_id,cat_name,Orderlist,weight) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddcat_id"]."' ";
$strSQL .=",'".$_POST["txtAddperiod_id"]."' ";
$strSQL .=",'".$_POST["txtAddcat_name"]."' ";
$strSQL .=",'".$_POST["txtAddOrderlist"]."' ";
$strSQL .=",'".$_POST["txtAddweight"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//Update
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE cf_ass_category SET ";
$strSQL .="period_id = '".$_POST["txtEditperiod_id"]."' ";
$strSQL .=",cat_name = '".$_POST["txtEditcat_name"]."' ";
$strSQL .=",Orderlist = '".$_POST["txtEditOrderlist"]."' ";
$strSQL .=",weight = '".$_POST["txtEditweight"]."' ";
$strSQL .="WHERE cat_id = '".$_POST["hdnEditcat_id"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//Delete
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM cf_ass_category ";
$strSQL .="WHERE cat_id = '".$_GET["cat_id"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
if($period_id){
$strSQL = "SELECT * FROM cf_ass_category where period_id='$period_id' ";
}else{
$strSQL = "SELECT * FROM cf_ass_category order by period_id ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<?php
//ต่อฐานข้อมูล
$link=mysql_connect("localhost","root","1234") or die("error".mysql_error());
mysql_select_db("evaluation",$link);
?>
<div align="center">
<select name="subject" id="subject" onchange="subject(''+this.value+'')">
<option value="">Please select</option>
<?php
$q="select * from cf_ass_period ";
$qr=mysql_query($q);
while($rs=mysql_fetch_array($qr)){
?>
<option value="<?=$rs['period_id']?>"><?=$rs['period_id']?> . <?=$rs['subject']?></option>
<?php } ?>
</select>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Evaluation</title>
<link rel="stylesheet" type="text/css" href="css/register.css" media="screen" title="Innovation Screen Style Sheet" />
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/register1.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/check-form.js"></script>
<html>
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<head>
</head>
<body>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<div align="center">
<input type="hidden" name="hdnCmd" value="">
</div>
<table width="600" border="1" align="center">
<tr>
<th width="91"> <div align="center">cat_id </div></th>
<th width="98"> <div align="center">Period_id </div></th>
<th width="97"> <div align="center">cat_Name </div></th>
<th width="97"> <div align="center">Orderlist </div></th>
<th width="97"> <div align="center">weight </div></th>
<th width="97"> <div align="center">Edit </div></th>
<th width="97"> <div align="center">Delete </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["cat_id"] == $_GET["cat_id"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="txtEditcat_id" size="5" value="<?=$objResult["cat_id"];?>">
<input type="hidden" name="hdnEditcat_id" size="5" value="<?=$objResult["cat_id"];?>"></div></td>
<td><input type="text" name="txtEditperiod_id" size="20" value="<?=$objResult["period_id"];?>"></td>
<td>
<input type="text" name="txtEditcat_name" size="80" value="<?=$objResult["cat_name"];?>"></div></td>
<td><input type="text" name="txtEditOrderlist" size="20" value="<?=$objResult["Orderlist"];?>"></td>
<td><input type="text" name="txtEditweight" size="20" value="<?=$objResult["weight"];?>"></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>?period_id=<?=$period_id?>';">
<input type="hidden" id="period_id" name="period_id" value="<?=$period_id?>" />
</div></td>
</tr>
<?
}
else
{
?>
<tr>
<td><div align="center"><?=$objResult["cat_id"];?></div></td>
<td><div align="center"><?=$objResult["period_id"];?></td>
<td><div align="center"><?=$objResult["cat_name"];?></td>
<td><div align="center"><?=$objResult["Orderlist"];?></td>
<td><div align="center"><?=$objResult["weight"];?></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&cat_id=<?=$objResult["cat_id"];?>&period_id=<?=$period_id?>"
style="color:#0033ff;margin-left:20px;">Edit</a></td>
<td align="center">
<a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&cat_id=<?=$objResult["cat_id"];?>
&period_id=<?=$period_id?>';}" style="color:#0033ff;margin-left:20px;">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center"><input type="text" name="txtAddcat_id" size="5"></div></td>
<td><div align="center"><input type="text" name="txtAddperiod_id" size="20" > </td>
<td><div align="center"><input type="text" name="txtAddcat_name" size="80"></td>
<td><div align="center"><input type="text" name="txtAddOrderlist" size="20"></td>
<td><div align="center"><input type="text" name="txtAddweight" size="20"></td>
<td colspan="2" align="right"><div align="center">
<input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick= "frmMain.hdnCmd.value='Add';frmMain.submit();">
</div></td>
</tr>
</table>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>
<script type="text/javascript">
function subject(value){
window.location='edit_category2.php?&period_id='+value;
}
</script>
Tag : PHP, CakePHP
|
|
|
|
|
|
Date :
2013-03-06 17:57:07 |
By :
jaiboon09 |
View :
948 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เงียบเลย รบกวนหน่อยนะครับ
|
|
|
|
|
Date :
2013-03-07 08:39:20 |
By :
jaiboon09 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
บอกหลักการน่ะครับ ใหคุณ sum ค่าทั้งหมด แล้วเก็บไว้ใน hidden จากนั้นใช้ javascript ตรวจสอบได้ง่าย ๆ ครับ
Code (JavaScript)
if(parseFloat(document.form.hdnSum.value) > 100)
{
alert('Please input sum less than <= 100');
return false;
}
ว่าง ๆ ลองเข้าไปอ่านบทความ JavaScript ครับ
|
|
|
|
|
Date :
2013-03-07 09:20:27 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากนะครับ อย่างไงเดียวรองดูครับ ได้ผลอย่างไงเดียวกลับมาตอบนะครับ. ขอบคุณครับ
|
|
|
|
|
Date :
2013-03-07 09:33:13 |
By :
konjaiboon |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|