  | 
              
	              
	                
  
    
	 
        มีปัญหาในการบันทึกข้อมูล แบบ ajax ครับไม่สามารถบันทึกลง db ได้     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                คือผมได้ลองนำบทความที่เกี่ยวกับบทความ ajax มาลองทำดูทำตาม code ทุกอย่างมันก็ทำงานปกติ แต่พอลองดัดแปลง code ค่าไม่ถูกบันทึกครับอยากให้พี่ๆๆช่วยผมดูหน่อยว่ามันผิดตำแหน่งตรงไหนรึป่าวผมลองหาจนตาลายแล้วยังไม่ได้เลยครับ 
 
form 
Code (PHP) 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<script language="JavaScript">
	   var HttPRequest = false;
	   function doCallAjax(Mode) {
		  HttPRequest = false;
		  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;
		  }
	
		  var url = 'test2.php';
		  var pmeters = "&TNAME=" + encodeURI( document.getElementById("NAME").value ) +
						"&TEMAIL=" + encodeURI( document.getElementById("EMAIL").value ) +
						"&TCODE=" + encodeURI( document.getElementById("CODE").value ) +
						"&TBUDGET=" + encodeURI( document.getElementById("BUDGET").value ) +
						
						"&tMode=" + Mode;
			HttPRequest.open('POST',url,true);
			HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			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;
				  
				   document.getElementById("NAME").value = '';
				   document.getElementById("EMAIL").value = '';
				   document.getElementById("CODE").value = '';
				   document.getElementById("BUDGET").value = '';
				  
				  }
				
			}
	   }
	</script>
<body Onload="JavaScript:doCallAjax('LIST');">
<h1>My Customer</h1>
<form name="frmMain">
<table width="480" border="1">
  <tr>
    <th width="98"> <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>
    </tr>
  <tr>
	<td><input type="text" name="NAME" id="NAME" size="20"></td>
	<td><input type="text" name="EMAIL" id="EMAIL" size="20"></td>
	<td><div align="center"><input type="text" name="CODE" id="CODE" size="2"></div></td>
	<td align="right"><input type="text" name="BUDGET" id="BUDGET" size="5"></td>
	</tr>
</table>
<input type="button" name="btnAdd" id="btnAdd" value="Add" OnClick="JavaScript:doCallAjax('ADD');">
<br><br>
<span id="mySpan"></span>
</form>
 
 
 
script 
Code (PHP) 
$strMode = $_POST["tMode"];
$name=$_POST["TNAME"];
$email=$_POST["TEMAIL"];
$code=$_POST["TCODE"];
$budget=$_POST["TBUDGET"];
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("customer");
if($strMode == "ADD"){
	
	
$sql = "SELECT CustomerID FROM  customer  ORDER BY  CustomerID DESC LIMIT 1";
$result = mysql_query($sql);
      if(mysql_num_rows($result) > 0){
	  
           $row = mysql_fetch_array($result);
           sscanf($row[0] ,"0%d" , $id); 
		   $id++;
 
 $sql = "INSERT INTO customer VALUES(CONCAT('0',RIGHT(CONCAT('0000' , $id) , 4)),'$name','$email','$code','$budget')"; 		   
      }
      else
      {
	  
 
 $sql = "INSERT INTO customer VALUES('00001','$name','$email','$code','$budget')";
      }
}
 
 
  Tag : PHP               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2011-07-28 16:44:31 | 
                      By :
                          chonburi f.c | 
                      View :
                          991 | 
                      Reply :
                          5 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ได้แล้วครับขอบคุณมากครับ ??                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-07-28 17:04:26 | 
                        By :
                            chonburi f.c | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 jquery ajax, jquery serialize อะไรๆ ก็ง๊ายยยง่าย                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-07-28 17:26:52 | 
                        By :
                            PlaKriM | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 รับค่าได้แล้วครับ ขอบคุณครับ   
 
ว่าแต่ $_request หมายความว่ายังไงครับผม                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2011-07-28 18:24:36 | 
                        By :
                            chonburi f.c | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |