  | 
              
	              
	                
  
    
	 
        จากหัวข้อสอน PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form มีเออเร่อ     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เอา code มาลงด้วยก็ดีนะครับ ที่แก้แล้วเป็นของตัวเอง                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-09-21 11:34:16 | 
                        By :
                            nobetaking | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เอาไว้บน connect นะครับ ลองดู 
Code (PHP) 
        ini_set('display_errors', 1);
        error_reporting(~0);
       
       $objConnect = mysql_connect("localhost","root","...") or die("Error Connect to Database");
       $objDB = mysql_select_db("...");
                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2018-09-21 11:56:16              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-09-21 11:55:01 | 
                        By :
                            nobetaking | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 มันขึ้น notic  น่าจะต้องใช้ isset ครอบก่อนเช็ค parameter  
Code (PHP) 
if(isset($_POST["hdnCmd"])) {
// bla bla
}
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-09-21 12:14:30 | 
                        By :
                            Luz | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   ตอบความคิดเห็นที่ : 3 เขียนโดย : nobetaking เมื่อวันที่ 2018-09-21 11:55:01 
รายละเอียดของการตอบ ::
  ... ใส่ความคิดเห็นตรงนี้.......ได้ล่ะครับ ติดอีกนิดนึงตรงผลไม่แสดงไม่เป็นภา็าไทยครับ เปนเครื่องหมาย ??????
  
 
ผมต้องเพิ่มอะไรตรงไหนครับ  
 
Code (PHP) 
<html>
<head>
 <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>ค้นหาสินทรัพย์</title>
    <!-- Bootstrap -->
    <link href="../../bootstrap/css/bootstrap.min.css" rel="stylesheet">
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?php
ini_set('display_errors', 1);
 error_reporting(0);
$objConnect = mysql_connect("localhost","root","...") or die("Error Connect to Database");
$objDB = mysql_select_db("...");
mysql_set_charset($objConnect, "utf8");
mysql_set_charset($objConnect, "utf8");
//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
	$strSQL = "INSERT INTO user_repair ";
	$strSQL .="(User_name) ";
	$strSQL .="VALUES ";
	$strSQL .="('".$_POST["User_name"]."','".$_POST["v"]."' ";
	$objQuery = mysql_query($strSQL);
	mysql_query($objConnect, "utf8");
	mysql_set_charset($objConnect, "utf8");
	if(!$objQuery)
	{
		echo "Error Save [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}
//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
	$strSQL = "UPDATE user_repair SET ";
	$strSQL .="User_Repair_ID = '".$_POST["txtEditUser_Repair_ID"]."' ";
	$strSQL .=",User_name = '".$_POST["txtEditUser_name"]."' ";
	$strSQL .=",Branch_ID = '".$_POST["txtEditBranch_ID"]."' ";
	$strSQL .=",Department_ID = '".$_POST["txtEditDepartment_ID"]."' ";
	$strSQL .=",Telephone = '".$_POST["txtEditTelephone"]."' ";
	$strSQL .=",Date_sent = '".$_POST["txtEditDate_sent"]."' ";
	$strSQL .=",Asset_ID = '".$_POST["txtEditAsset_ID"]."' ";
	$strSQL .=",Asset_re_detail = '".$_POST["txtEditAsset_re_detail"]."' ";
	$strSQL .=",Date_finish = '".$_POST["txtEditDate_finish"]."' ";
	$strSQL .="WHERE User_Repair_ID = '".$_POST["hdnEditUser_Repair_ID"]."' ";
	$objQuery = mysql_query($strSQL);
	mysql_query($objConnect, "utf8");
	mysql_set_charset($objConnect, "utf8");
	if(!$objQuery)
	{
		echo "Error Update [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}
//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
	$strSQL = "DELETE FROM user_repair ";
	$strSQL .="WHERE User_Repair_ID = '".$_GET["RepairID"]."' ";
	$objQuery = mysql_query($strSQL);
	mysql_query($objConnect, "utf8");
	mysql_set_charset($objConnect, "utf8");
	if(!$objQuery)
	{
		echo "Error Delete [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}
 mysql_query($objConnect, "utf8");
mysql_set_charset($objConnect, "utf8");
$strSQL = "SELECT * FROM asset a
inner JOIN user_repair u ON a.Asset_ID = u.Asset_ID
LEFT JOIN branch b1 ON a.Branch_ID = b1.Branch_ID
LEFT JOIN department d on a.Department_ID = d.Department_ID";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
mysql_query($objConnect, "utf8");
mysql_set_charset($objConnect, "utf8");
?>
<form name="frmMain" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="1040" border="1">
  <tr>
    <th width="66"> <div align="center">No. </div></th>
       <th width="136"> <div align="center">ชื่อผู้แจ้ง </div></th>
    <th width="121"> <div align="center">วันที่ส่ง </div></th>
    <th width="163"> <div align="center">อาการ </div></th>
    <th width="109"> <div align="center">วันที่เสร็จ </div></th>
    <th width="100"> <div align="center">Edit </div></th>
    <th width="100"> <div align="center">Delete </div></th>
  </tr>
<?php
while($objResult = mysql_fetch_array($objQuery))
{
?>
  <?php
	if($objResult["User_Repair_ID"] == $_GET["RepairID"] and $_GET["Action"] == "Edit")
	{
  ?>
  <tr>
    <td><div align="center">
		<input name="txtEditUser_Repair_ID" type="text" value="<?php echo $objResult["User_Repair_ID"];?>" size="2" readonly>
		<input type="hidden" name="hdnEditUser_Repair_ID" size="2" value="<?php echo $objResult["User_Repair_ID"];?>">
	</div></td>
      <td><input type="text" name="txtEditUser_name" size="15" value="<?php echo $objResult["User_name"];?>"></td>
    <td><div align="center"><input type="text" name="txtEditDate_sent" size="10" value="<?php echo $objResult["Date_sent"];?>"></div></td>
    <td align="left"><input type="text" name="txtEditAsset_re_detail" size="25" value="<?php echo $objResult["Asset_re_detail"];?>"></td>
    <td align="left"><input type="text" name="txtEditDate_finish" size="10" value="<?php echo $objResult["Date_finish"];?>"></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='<?php echo $_SERVER["PHP_SELF"];?>';">
    </div></td>
  </tr>
  <?php
	}
  else
	{
  ?>
  <tr>
    <td><div align="center"><?php echo $objResult["User_Repair_ID"];?></div></td>
     <td><div align="center"><?php echo $objResult["User_name"];?></div></td>
    <td align="right"><?php echo $objResult["Date_sent"];?></td>
    <td align="right"><?php echo $objResult["Asset_re_detail"];?></td>
    <td align="right"><?php echo $objResult["Date_finish"];?></td>
    <td align="center"><a href="<?php echo $_SERVER["PHP_SELF"];?>?Action=Edit&RepairID=<?php echo $objResult["User_Repair_ID"];?>">Edit</a></td>
	<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?php echo $_SERVER["PHP_SELF"];?>?Action=Del&RepairID=<?php echo $objResult["User_Repair_ID"];?>';}">Delete</a></td>
  </tr>
  <?php
	}
  ?>
<?php
}
?>
 
</table>
</form>
<?php
mysql_close($objConnect);
?>
</body>
</html>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-09-21 14:59:10 | 
                        By :
                            sweerawat | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ลองใส่ @ ดูครับ 
Code (PHP) 
if(@$_POST["hdnCmd"] == "Add")
if(@$_POST["hdnCmd"] == "Update")
if(@$_GET["Action"] == "Del")
                         
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-09-21 16:32:00 | 
                        By :
                            Jatmentz | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ตรง connect ฐานข้อมูลครับ ลองปรับเป็นประมาณนี้ดูครับ 
Code (PHP) 
        $objConnect = mysql_connect("$serverName","$userName","$userPassword") or die("Error Connect to Database");
	$objDB = mysql_select_db("databass");
	mysql_query("SET character_set_results=utf8");
	mysql_query("SET character_set_client=utf8");
	mysql_query("SET character_set_connection=utf8");
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-09-24 10:39:27 | 
                        By :
                            nobetaking | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |