|
|
|
ทำไมมันแก้ไขข้อมูลไม่ได้ค่ะ พี่ๆช่วยดูไห้ที ไม่รู้เป็นไร |
|
|
|
|
|
|
|
ทำไมมันแก้ไขข้อมูลไม่ได้ พอแก้แล้วข้อมูลที่แก้ก็ว่างเปล่า แต่เวลาทีเอาโค็ด(ตัวหนาในโค๊ด)ออก มันกลับแก้ไขได้ หนูงงค่ะ
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
session_start();
if($_SESSION['Mem_ID'] == "")
{
echo "Please Login!";
echo sss.$_SESSION['Mem_ID'];
exit();
}?>
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript">
$(function(){
// แทรกโค้ต jquery
$("#dateInput").datepicker({ dateFormat: 'yy-mm-dd' });
});
</script>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("household");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO income ";
$strSQL .="(Inc_Type_ID,Mem_ID,Inc_Amount,Inc_Date,Inc_Note) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["Inc_Type_ID"]."','".$_SESSION['Mem_ID']."' ";
$strSQL .=",'".$_POST["Inc_Amount"]."' ";
$strSQL .=",'".$_POST["Inc_Date"]."','".$_POST["Inc_Note"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE income SET ";
$strSQL .="Inc_Type_ID = '".$_POST["Inc_Type_ID"]."' ";
$strSQL .=",Mem_ID = '".$_SESSION['Mem_ID']."' ";
$strSQL .=",Inc_Amount = '".$_POST["Inc_Amount"]."' ";
$strSQL .=",Inc_Date = '".$_POST["Inc_Date"]."' ";
$strSQL .=",Inc_Note = '".$_POST["Inc_Note"]."' ";
$strSQL .="WHERE Inc_ID = '".$_POST["Inc_ID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM income ";
$strSQL .="WHERE Inc_ID = '".$_GET["Inc_ID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM income WHERE Mem_ID LIKE '".$_SESSION['Mem_ID']."' ORDER BY Mem_ID ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">ประเภท </div></th>
<th width="98"> <div align="center">รายรับ </div></th>
<th width="198"> <div align="center">วันที่ </div></th>
<th width="97"> <div align="center">หมายเหตุ </div></th>
<th width="59"> <div align="center">แก้ไข </div></th>
<th width="71"> <div align="center">ลบ </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["Inc_ID"] == $_GET["Inc_ID"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="Inc_Type_ID" size="5" value="<?=$objResult1["Inc_Type_ID"];?>">
<input type="hidden" name="Inc_ID" size="5" value="<?=$objResult["Inc_ID"];?>">
</div></td>
<td><input type="text" name="Inc_Amount" size="20" value="<?=$objResult["Inc_Amount"];?>"></td>
<td><input type="text" name="Inc_Date" size="2" value="<?=$objResult["Inc_Date"];?>"></div></td>
<td><input type="text" name="Inc_Note" size="5" value="<?=$objResult["Inc_Note"];?>"></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"];?>';">
</div></td>
</tr>
<?
}
else
{
$strJoin="SELECT income.*,income_type.* FROM income,income_type WHERE income.Inc_Type_ID = income_type.Inc_Type_ID AND income.Inc_Type_ID = '".$objResult["Inc_Type_ID"]."'";
$objQuery1 = mysql_query($strJoin) or die ("Error Query [".$strJoin."]");
$objResult1 = mysql_fetch_array($objQuery1);
?>
<tr>
<td><?=$objResult1["Inc_Type_Name"];?></td>
<td><?=$objResult["Inc_Amount"];?></td>
<td><?=$objResult["Inc_Date"];?></td>
<td><?=$objResult["Inc_Note"];?></td>
<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&Inc_ID=<?=$objResult["Inc_ID"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&Inc_ID=<?=$objResult["Inc_ID"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<? $strSQL = "SELECT * FROM income_type";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");?>
<td><div align="center"><select name="Inc_Type_ID" id="">
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<option value="<?=$objResult["Inc_Type_ID"];?>"><?=$objResult["Inc_Type_Name"];?></option>
<?
}
?>
</select></div></td>
<td><input type="text" name="Inc_Amount" size="20"></td>
<td><input type="text" name="Inc_Date" value="<?php echo date('Y-m-d') ?>"></td>
<td><input type="text" name="Inc_Note" size="5"></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>
Tag : PHP
|
|
|
|
|
|
Date :
2013-04-08 19:55:07 |
By :
nongtoom |
View :
768 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผิดตรง
<input type="text" name="Inc_Type_ID" size="5" value="<?=$objResult["Inc_Type_ID"];?>">
พอดีใส่ 1 ไป
|
|
|
|
|
Date :
2013-05-26 11:52:54 |
By :
nongtoom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|