|
 |
|
เอาโค้ดจากเว็บไปใช้ มันกด แก้ไข และ กด ลบ ไม่ได้ แต่ว่ากด เพิ่มข้อมูลได้คะ |
|
 |
|
|
 |
 |
|
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","suky") or die("Error Connect to Database");
$objDB = mysql_select_db("carrentalonlinesystem");
mysql_query("SET NAMES UTF8");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
$sql="INSERT INTO employee (employeeid, fname, lname, username, password, birthday, address, phoneno, position, salary) VALUES ('".$_POST["Addemployeeid"]."','".$_POST["Addfname"]."','".$_POST["Addlname"]."','".$_POST["Addusername"]."','".$_POST["Addpasswd"]."','".$_POST["Addbirthday"]."','".$_POST["Addaddress"]."','".$_POST["Addphoneno"]."','".$_POST["Addposition"]."','".$_POST["Addsalary"]."' )";
$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 customer SET ";
$strSQL .="employeeid = '".$_POST["Editemployeeid"]."' ";
$strSQL .=",fname = '".$_POST["Editfname"]."' ";
$strSQL .=",lname = '".$_POST["Editlname"]."' ";
$strSQL .=",username = '".$_POST["Editusername"]."' ";
$strSQL .=",password = '".$_POST["Editpasswd"]."' ";
$strSQL .=",birthday = '".$_POST["Editbirthday"]."' ";
$strSQL .=",address = '".$_POST["Editaddress"]."' ";
$strSQL .=",phoneno = '".$_POST["Editphoneno"]."' ";
$strSQL .=",position = '".$_POST["Editposition"]."' ";
$strSQL .=",salary = '".$_POST["Editsalary"]."' ";
$strSQL .="WHERE employeeid = '".$_POST["hdnEditemployeeid"]."' ";
$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 employee ";
$strSQL .="WHERE employeeid = '".$_GET["employeeid"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}
$strSQL = "SELECT * FROM employee";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["file:///C|/Documents and Settings/Owner/My Documents/Downloads/20091018174410/PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="1500" border="1">
<tr>
<th width="90" align="center"> <div align="center">รหัสพนักงาน </div></th>
<th width="160" align="center"> <div align="center">ชื่อ</div></th>
<th width="198" align="center"> <div align="center">สกุล</div></th>
<th width="90" align="center"> <div align="center">รหัสผู้ใช้ </div></th>
<th width="90" align="center"> <div align="center">รหัสผ่าน </div></th>
<th width="100" align="center"> <div align="center">วันเกิด </div></th>
<th width="250" align="center"> <div align="center">ที่อยู่ </div></th>
<th width="90" align="center"> <div align="center">เบอร์โทรศัพท์ </div></th>
<th width="90" align="center"> <div align="center">ตำแหน่ง </div></th>
<th width="90" align="center"> <div align="center">เงินเดือน </div></th>
<th width="30" align="center"> <div align="center">การจัดการ </div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<?
if($objResult["employeeid"] == $_GET["Editemployeeid"] and $_GET["Action"] == "Edit")
{
?>
<tr>
<td><div align="center">
<input type="text" name="Editemployeeid" size="5" value="<?=$objResult["employeeid"];?>">
<input type="hidden" name="hdnEditemployeeid" size="5" value="<?=$objResult["employeeid"];?>">
</div></td>
<td><input type="text" name="Editfname" size="20" value="<?=$objResult["fname"];?>"></td>
<td><input type="text" name="Editlname" size="20" value="<?=$objResult["lname"];?>"></td>
<td><input type="text" name="Editusername" size="2" value="<?=$objResult["username"];?>"></div></td>
<td><input type="text" name="Editpasswd" size="5" value="<?=$objResult["password"];?>"></td>
<td><input type="text" name="Editbirthday" size="5" value="<?=$objResult["birthday"];?>"></td>
<td><input type="text" name="taddress" size="20" value="<?=$objResult["address"];?>"></td>
<td><input type="text" name="Editphoneno" size="20" value="<?=$objResult["phoneno"];?>"></td>
<td><input type="text" name="Editposition" size="2" value="<?=$objResult["position"];?>"></div></td>
<td align="right"><input type="text" name="Editsalary" size="5" value="<?=$objResult["salary"];?>"></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
{
?>
<tr>
<td><div align="center"><?=$objResult["employeeid"];?></div></td>
<td><?=$objResult["fname"];?></td>
<td><?=$objResult["lname"];?></td>
<td><?=$objResult["username"];?></td>
<td><?=$objResult["password"];?></td>
<td><?=$objResult["birthday"];?></td>
<td><?=$objResult["address"];?></td>
<td><?=$objResult["phonrno"];?></td>
<td><?=$objResult["position"];?></td>
<td><?=$objResult["salary"];?></td>
<td align="right"><a href="<?=$_SERVER["phpMySQLAddEditDeleteRecord.php"];?>?Action=Edit&CusID=<?=$objResult["employeeid"];?>">Edit</a></td>
<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&CusID=<?=$objResult["employeeid"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<tr>
<td><div align="center"><input type="text" name="Addemployeeid" size="5"></div></td>
<td><input type="text" name="Addfname" size="20"></td>
<td><input type="text" name="Addlname" size="20"></td>
<td><input type="text" name="Addusername" size="2"></td>
<td><input type="text" name="Addpasswd" size="5"></td>
<td><input type="text" name="Addbirthday" size="5"></td>
<td><input type="text" name="Addaddress" size="20"></td>
<td><input type="text" name="Addphoneno" size="2"></td>
<td><input type="text" name="Addposition" size="5"></td>
<td align="right"><input type="text" name="Addsalary" 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, MySQL

|
|
 |
 |
 |
 |
Date :
2014-01-21 14:34:16 |
By :
sukyzero |
View :
656 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เขียนเองเลยครับ ^^ ง่ายกว่าเยอะ ดู code คนอื่นแล้ว งงๆ เช็ค filed ไอดี ฐานข้อมูลดีๆครับ
ปล.ยินดีช่วยเหลือครับ
https://www.facebook.com/chaosiam
|
 |
 |
 |
 |
Date :
2014-01-21 14:44:11 |
By :
chaosiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พอดีไม่เก่งอะคะ เลยไม่ถนัด อาศัยก็อปโค้ดเอา
|
 |
 |
 |
 |
Date :
2014-01-21 14:53:27 |
By :
sukyzero |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|