Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > กดปุ่ม cancel หรือ delete แล้วข้อมูลที่แสดงมันจะหายไปไม่แสดง



 

กดปุ่ม cancel หรือ delete แล้วข้อมูลที่แสดงมันจะหายไปไม่แสดง

 



Topic : 084522



โพสกระทู้ ( 157 )
บทความ ( 0 )



สถานะออฟไลน์




AjaxPHPEditRecord1.php

Code (PHP)
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<script language="JavaScript">
	   var HttpRequest = false;

		<!-- // ********************************* -->
		function checkBrowser(){
				  if (window.XMLHttpRequest) { // Mozilla, Safari,...
					 HttpRequest = new XMLHttpRequest();
					 if (HttpRequest.overrideMimeType) {
						HttpRequest.overrideMimeType('text/html');
					 }
				  } else if (window.ActiveXObject) { // IE
					 try {
						HttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
					 } catch (e) {
						try {
						   HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
						} catch (e) {}
					 }
				  }

				  if (!HttpRequest) {
					 alert('Cannot create XMLHTTP instance');
					 return false;
				  }
		}
		<!-- //************************************** -->

	   function doCallAjax(Mode) {
		  HttpRequest = false;
		  checkBrowser();

		  var url = 'AjaxPHPEditRecord2.php';

		  if(Mode == "ADD") {
			var	pmeters = "tCustomerID=" + encodeURI( document.getElementById("atxtCustomerID").value) +
							"&tName=" + encodeURI( document.getElementById("atxtName").value ) +
							"&tEmail=" + encodeURI( document.getElementById("atxtEmail").value ) +
							"&tCountryCode=" + encodeURI( document.getElementById("atxtCountryCode").value ) +
							"&tBudget=" + encodeURI( document.getElementById("atxtBudget").value ) +
							"&tUsed=" + encodeURI( document.getElementById("atxtUsed").value ) +
							"&tMode=" + Mode;
				alert(pmeters);
		  }

		  if(Mode == "UPDATE") {
			  var pmeters = "tCustomerID=" + encodeURI( document.getElementById("txtCustomerID").value) +
							"&tName=" + encodeURI( document.getElementById("txtName").value ) +
							"&tEmail=" + encodeURI( document.getElementById("txtEmail").value ) +
							"&tCountryCode=" + encodeURI( document.getElementById("txtCountryCode").value ) +
							"&tBudget=" + encodeURI( document.getElementById("txtBudget").value ) +
							"&tUsed=" + encodeURI( document.getElementById("txtUsed").value ) +
							"&tMode=" + Mode;
		  }

		  if(Mode == "LIST") {
			var	pmeters = "";
		  }

			HttpRequest.open('POST',url,true);

			HttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
			HttpRequest.setRequestHeader("Content-length", pmeters.length);
			HttpRequest.setRequestHeader("Connection", "close");
			HttpRequest.send(pmeters);


			HttpRequest.onreadystatechange = function()
			{

				 if(HttpRequest.readyState == 3)  // Loading Request
				  {
					   document.getElementById("mySpan").innerHTML = "<image src='images/ajax_load.gif'>";
				  }

				 if(HttpRequest.readyState == 4) // Return Request
				  {
				    document.getElementById("editForm").style.display = 'none';
				    document.getElementById("addForm").style.display = 'none';
					document.getElementById("startAdd").style.display = '';

				   document.getElementById("txtCustomerID").value = '';
				   document.getElementById("txtName").value = '';
				   document.getElementById("txtEmail").value = '';
				   document.getElementById("txtCountryCode").value = '';
				   document.getElementById("txtBudget").value = '';
				   document.getElementById("txtUsed").value = '';

				   document.getElementById("mySpan").innerHTML = HttpRequest.responseText;


				  }

			}

	   }

	   function ShowADD() {

			 document.getElementById("addForm").style.display = '';
			 document.getElementById("editForm").style.display = 'none';
			 document.getElementById("startAdd").style.display = 'none';

			document.getElementById("atxtCustomerID").value ='';
			document.getElementById("atxtName").value = '';
			document.getElementById("atxtEmail").value = '';
			document.getElementById("atxtCountryCode").value ='';
			document.getElementById("atxtBudget").value ='';
			document.getElementById("atxtUsed").value = '';
	   }


	   function ShowEdit(sCustomerID,sName,sEmail,sCountryCode,sBudget,sUsed) {

			document.getElementById("editForm").style.display = '';
			document.getElementById("addForm").style.display = 'none';
			 document.getElementById("startAdd").style.display = 'none';

			document.getElementById("txtCustomerID").value = sCustomerID;
			document.getElementById("txtName").value = sName;
			document.getElementById("txtEmail").value = sEmail;
			document.getElementById("txtCountryCode").value = sCountryCode;
			document.getElementById("txtBudget").value = sBudget;
			document.getElementById("txtUsed").value = sUsed;
	   }


	 	function ajaxDelete(Mode, txtCustomerID) {
				HttpRequest = false;
				checkBrowser();
				//alert('test');
				var url = 'AjaxPHPEditRecord2.php';
				var pmeters = "tCustomerID=" + txtCustomerID + "&tMode=" + Mode;

				HttpRequest.open('POST',url,true);
				HttpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");
				HttpRequest.setRequestHeader("Content-length", pmeters.length);
				HttpRequest.setRequestHeader("Connection", "close");
				HttpRequest.send(pmeters);

				HttpRequest.onreadystatechange = function(){

					 if(HttpRequest.readyState == 3)  // Loading Request
					  {
						  document.getElementById("mySpan").innerHTML = "Now is Loading...";
					  }

					 if(HttpRequest.readyState == 4) // Return Request
					  {
						  // document.getElementById("mySpan").innerHTML = HttpRequest.responseText;
						  doCallAjax('LIST');
					  }
				}

		}

	</script>

<body Onload="JavaScript:doCallAjax('LIST');">
<h1>My Customer</h1>
<form name="frmMain">
<span id="editForm" style="display='none';">
		<table width="700" border="1">
		  <tr>
				<th width="91">CustomerID</th>
				<th width="98">Name</th>
				<th width="198">Email</th>
				<th width="97">CountryCode</th>
				<th width="59">Budget</th>
				<th width="71">Used</th>
		  </tr>

		  <tr>
				<td><input type="text" name="txtCustomerID" id="txtCustomerID" size="5"></td>
				<td><input type="text" name="txtName" id="txtName" size="25"></td>
				<td><input type="text" name="txtEmail" id="txtEmail" size="25"></td>
				<td><input type="text" name="txtCountryCode" id="txtCountryCode" size="2"></td>
				<td align="right"><input type="text" name="txtBudget" id="txtBudget" size="5"></td>
				<td align="right"><input type="text" name="txtUsed" id="txtUsed" size="5"></td>
		  </tr>
		</table>

		<input type="button" name="btnUpdate" id="btnUpdate" value="Update" OnClick="JavaScript:doCallAjax('UPDATE');">
		<input type="button" name="btnCancelUpdate" id="btnCancelUpdate" value="CancelUpdate" OnClick="JavaScript:doCallAjax('LIST');">
		<br><br>
</span>


<span id="addForm" style="display='none';">
		<table width="700" border="1">
		  <tr>
				<th width="91">CustomerID</th>
				<th width="98">Name</th>
				<th width="198">Email</th>
				<th width="97">CountryCode</th>
				<th width="59">Budget</th>
				<th width="71">Used</th>
		  </tr>

		  <tr>
				<td><input name="atxtCustomerID" type="text" id="atxtCustomerID" size="5"></td>
				<td><input type="text" name="atxtName" id="atxtName" size="25"></td>
				<td><input type="text" name="atxtEmail" id="atxtEmail" size="25"></td>
				<td><input type="text" name="atxtCountryCode" id="atxtCountryCode" size="2"></td>
				<td align="right"><input type="text" name="atxtBudget" id="atxtBudget" size="5"></td>
				<td align="right"><input type="text" name="atxtUsed" id="atxtUsed" size="5"></td>
		  </tr>
		</table>

		<input type="button" name="btnADD" id="btnADD" value="ADD" OnClick="JavaScript:doCallAjax('ADD');">
		<input type="button" name="btnCancelADD" id="btnCancelADD" value="CancelADD" OnClick="JavaScript:doCallAjax('LIST');">
		<br><br>
</span>

<div id="startAdd" style="display='none';">
	<input type="button" name="btnShowADD" id="btnShowADD" value="ADD" OnClick="JavaScript:ShowADD();">
</div>

<span id="mySpan"></span>
</form>
</body>
</html>




AjaxPHPEditRecord1.php
Code (PHP)
<?
session_start();
$ss= $_SESSION['name']=$_POST['tName'];
?>
<html>
<head>
<title></title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php
include "../config.inc.php";
mysql_select_db('customer');

$strMode = $_POST["tMode"];
$strID = $_POST["tCustomerID"];

if($strMode == "ADD") {
	$strSQL = "INSERT INTO customer SET ";
	$strSQL .="CustomerID = '".$_POST["tCustomerID"]."' ";
	$strSQL .=",Name = '".$_POST["tName"]."' ";
	$strSQL .=",Email = '".$_POST["tEmail"]."' ";
	$strSQL .=",CountryCode = '".$_POST["tCountryCode"]."' ";
	$strSQL .=",Budget = '".$_POST["tBudget"]."' ";
	$strSQL .=",Used = '".$_POST["tUsed"]."' ";
		// $strSQL .="WHERE CustomerID = '".$_POST["tCustomerID"]."' ";
	$objQuery = mysql_query($strSQL);

} else if($strMode == "UPDATE") {
	$strSQL = "UPDATE customer SET ";
	$strSQL .="Name = '".$_POST["tName"]."' ";
	$strSQL .=",Email = '".$_POST["tEmail"]."' ";
	$strSQL .=",CountryCode = '".$_POST["tCountryCode"]."' ";
	$strSQL .=",Budget = '".$_POST["tBudget"]."' ";
	$strSQL .=",Used = '".$_POST["tUsed"]."' ";
	$strSQL .="WHERE CustomerID = '".$_POST["tCustomerID"]."' ";
	$objQuery = mysql_query($strSQL);

} else if($strMode == "DELETE") {
	$strSQL = "DELETE FROM customer ";
	$strSQL .="WHERE CustomerID = '".$strID."' ";
	$objQuery = mysql_query($strSQL);
}

echo "$ss";
$strSQL = "SELECT * FROM customer WHERE  Name ='$ss' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="700" border="1">
  <tr>
    <th width="91"> <div align="center">CustomerID</div></th>
    <th width="158"> <div align="center">Name</div></th>
    <th width="198"> <div align="center">Email</div></th>
    <th width="97"> <div align="center">CountryCode</div></th>
    <th width="59"> <div align="center">Budget</div></th>
    <th width="71"> <div align="center">Used</div></th>
    <th width="40"> <div align="center">Edit</div></th>
	 <th width="40"> <div align="center">Delete</div></th>
  </tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
  <tr>
    <td><div align="center"><?=$objResult["CustomerID"];?></div></td>
    <td><?=$objResult["Name"];?></td>
    <td><?=$objResult["Email"];?></td>
    <td><div align="center"><?=$objResult["CountryCode"];?></div></td>
    <td align="right"><?=$objResult["Budget"];?></td>
    <td align="right"><?=$objResult["Used"];?></td>
    <td align="center"><a href="JavaScript:ShowEdit('<?=$objResult["CustomerID"];?>','<?=$objResult["Name"];?>','<?=$objResult["Email"];?>','<?=$objResult["CountryCode"];?>','<?=$objResult["Budget"];?>','<?=$objResult["Used"];?>')">Edit</a></td>

	<td align="center"><a href="JavaScript:ajaxDelete('DELETE','<?=$objResult["CustomerID"];?>');" onClick="return confirm('Are you sure you want to delete?')">Del</a></td>
  </tr>
<?
}
?>
</table>

</body>
</html>


///////////////////////////////////////////


Code (PHP)
$strSQL = "SELECT * FROM customer WHERE  Name ='$ss' ";


ถ้าไม่ใส่ where มันจะแสดงทั้งหมด



Tag : PHP, Ajax









ประวัติการแก้ไข
2012-09-26 17:02:16
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-09-25 13:27:56 By : praphat_thekop View : 1025 Reply : 4
 

 

No. 1



โพสกระทู้ ( 157 )
บทความ ( 0 )



สถานะออฟไลน์


ถ้า ใส่แค่นี้ดูได้ไม่หาย

Code (PHP)
$strSQL = "SELECT * FROM customer ";







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-25 15:44:55 By : praphat_thekop
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ลองดูใน php ครับ มันส่งค่าไปหรือเปล่าครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-28 09:34:59 By : mr.win
 

 

No. 3



โพสกระทู้ ( 157 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : mr.win เมื่อวันที่ 2012-09-28 09:34:59
รายละเอียดของการตอบ ::


ส่งนะครับผม echo แล้วมันก็ส่งนะครับ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-09-28 11:32:18 By : praphat_thekop
 


 

No. 4



โพสกระทู้ ( 157 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 2 เขียนโดย : mr.win เมื่อวันที่ 2012-09-28 09:34:59
รายละเอียดของการตอบ ::
ช่วยด้วยครับงานเร่งมาก
เอาแค่่เพิ่มกับลบก็ได้ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-02 17:36:06 By : praphat_thekop
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : กดปุ่ม cancel หรือ delete แล้วข้อมูลที่แสดงมันจะหายไปไม่แสดง
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่