  | 
              
	              
	                
  
    
	 
        สร้างช่องรันเลขอัตโนมัติ insert ข้อมูล ผ่าน แต่ใน database เป็นค่าว่าง     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                รบกวนดูโค้ดให้หน่อยค่ะ 
ตรงที่ทำตัวหนาไว้ 
 
train.php (PHP) 
<?php
	session_start();
	require ('connectdb.php');	
	if($_SESSION['userid'] == ""){
									header("Content-type: text/html; charset=utf-8");
									echo"<script language='JavaScript' >";
									echo"alert('กรุณากรอกข้อมูลเพื่อเข้าสู่ระบบ');";
									echo"</script>";		
	exit(); 
	}
    ?>
<? include("f_thaidate.php");?>
<? include("datepick/datepick.php"); ?>
<html>
<head>
<title>Training Record System</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="img/icon/logo-ico.png"> 
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>	
		<h2>บันทึกการฝึกอบรม</h2>
		<form action='train_save.php' method='post'>
		<table class="table table-bordered">
			<tr >
			
			<?
				$sql="select MAX(tbtraining.trainingcode) as tcode from tbtraining";
				$objQuery=sqlsrv_query($conn,$sql);
				$row=sqlsrv_fetch_array($objQuery);
				$num=sqlsrv_num_rows($objQuery);
				if($num>0){
					$tcode=$row["tcode"]+1;				
				}else{
					$tcode=1;				
				}
				
			?>
				<td colspan="1">หลักสูตร   </td>
				<td colspan="6">
					<select name="addcourse">
						<option>เลือกหลักสูตร</option>
						<?php
							$strSQL = "select*from tbtopics";
							$objQuery = sqlsrv_query($conn,$strSQL);
							while($objResult = sqlsrv_fetch_array($objQuery)){
						?>
						<option value="<?php echo $objResult["topicsid"];?>"><?php echo $objResult["topicsname"];?></option>
						<?php }?>
					</select>
				</td>
				<td><input type="text" name="addtrcode" value="<?php echo $tcode;?>" style="width:100px;"></td>
				
			</tr>
			<tr>
				<td colspan="1">วันที่อบรม </td>
				<td colspan="4"><input type="date" name="addtraindate" value=""></td>
				<td colspan="3">จำนวน   <input type="text" name="addhrs" value="">   ชั่วโมง</td>
				
			</tr>
            	
			<tr>
				<td colspan="1">สถานที่อบรม</td>
				<td colspan="3">
					<select name="addplace">
						<option>เลือกสถานที่</option>
						<?php
							$strSQL = "select*from tbplace";
							$objQuery = sqlsrv_query($conn,$strSQL);
							while($objResult = sqlsrv_fetch_array($objQuery)){
						?>
						<option value="<?php echo $objResult["placeid"];?>"><?php echo $objResult["placename"];?></option>
							<?php }?>
					</select></td>
				<td colspan="2">ค่าใช้จ่าย    <input type="text" name="addcost" style="width:100px;">  บาท</td>
				<td colspan="2">วิทยากร   <input type="text" name="addtrainer" style="width:200px;"></td>
				
			</tr>
			<tr><td colspan="1">หมายเหตุ</td><td colspan="7"><input type="text" name="addremark" style="width:611px;"></td></tr>
	
		
		</table>
		
		<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>บันทึก</button>
		<a href="home.php" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>ยกเลิก</a>
		</form>
</body>
</html>
 
 
ต้องการให้บันทึกลงใน ฟิล trainingcode 
train_save.php (PHP) 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?PHP
include("connectdb.php");
$strSQL = "INSERT INTO tbtraining ";
$strSQL .="(trainingdate,topicsid,traininghours,placeid,trainingexpense,trainername,trainingremark,trainingcode)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["addtraindate"]."','".$_POST["addcourse"]."','".$_POST["addhrs"]."','".$_POST["addplace"]."' ";
$strSQL .=",'".$_POST["addcost"]."','".$_POST["addtrainer"]."','".$_POST["addremark"]."','".$POST["addtrcode"]."') ";
$objQuery = sqlsrv_query($conn,$strSQL);
if($objQuery){
	header("location:home.php");
}
else
{
	echo " Error Save [".$strSQL."] ";
}
sqlsrv_close($conn);
?>
 
 
บันทึกผ่านแต่ใน database กลับเป็นค่าว่าง 
  
 
ทั้งที่ในหน้าจอบันทึกมีข้อมูลตรงเลข 1 ค่ะ 
 
 
 
  Tag : PHP, Ms SQL Server 2008               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2017-11-27 15:43:12 | 
                      By :
                          bonusxi | 
                      View :
                          2255 | 
                      Reply :
                          4 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 <u>trainingcode</u>....? What the F**k 
 
<u>'".$POST["addtrcode"]."'</u> ...? 
 
คืออะไรครับ งงไม่เข้าใจ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-11-27 16:02:42 | 
                        By :
                            Hararock | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   ตอบความคิดเห็นที่ : 1 เขียนโดย : Hararock เมื่อวันที่ 2017-11-27 16:02:42 
รายละเอียดของการตอบ ::
  จะใส่ให้มันขีดเส้นใต้อะค่ะ คิดซะว่ามันไม่มีตัวนั้น
  
 
วางโค้ดให้ใหม่ค่ะ 
train.php Code (PHP) 
<?php
	session_start();
	require ('connectdb.php');	
	if($_SESSION['userid'] == ""){
									header("Content-type: text/html; charset=utf-8");
									echo"<script language='JavaScript' >";
									echo"alert('กรุณากรอกข้อมูลเพื่อเข้าสู่ระบบ');";
									echo"</script>";		
	exit(); 
	}
    ?>
<? include("f_thaidate.php");?>
<? include("datepick/datepick.php"); ?>
<html>
<head>
<title>Training Record System</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="img/icon/logo-ico.png"> 
<link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>	
		<h2>บันทึกการฝึกอบรม</h2>
		<form action='train_save.php' method='post'>
		<table class="table table-bordered">
			<tr >
			
			<?
				$sql="select MAX(tbtraining.trainingcode) as tcode from tbtraining";
				$objQuery=sqlsrv_query($conn,$sql);
				$row=sqlsrv_fetch_array($objQuery);
				$num=sqlsrv_num_rows($objQuery);
				if($num>0){
					$tcode=$row["tcode"]+1;				
				}else{
					$tcode=1;				
				}
				
			?>
				<td colspan="1">หลักสูตร   </td>
				<td colspan="6">
					<select name="addcourse">
						<option>เลือกหลักสูตร</option>
						<?php
							$strSQL = "select*from tbtopics";
							$objQuery = sqlsrv_query($conn,$strSQL);
							while($objResult = sqlsrv_fetch_array($objQuery)){
						?>
						<option value="<?php echo $objResult["topicsid"];?>"><?php echo $objResult["topicsname"];?></option>
						<?php }?>
					</select>
				</td>
				<td><input type="text" name="addtrcode" value="<?php echo $tcode;?>" style="width:100px;"></td>
				
			</tr>
			<tr>
				<td colspan="1">วันที่อบรม </td>
				<td colspan="4"><input type="date" name="addtraindate" value=""></td>
				<td colspan="3">จำนวน   <input type="text" name="addhrs" value="">   ชั่วโมง</td>
				
			</tr>
            	
			<tr>
				<td colspan="1">สถานที่อบรม</td>
				<td colspan="3">
					<select name="addplace">
						<option>เลือกสถานที่</option>
						<?php
							$strSQL = "select*from tbplace";
							$objQuery = sqlsrv_query($conn,$strSQL);
							while($objResult = sqlsrv_fetch_array($objQuery)){
						?>
						<option value="<?php echo $objResult["placeid"];?>"><?php echo $objResult["placename"];?></option>
							<?php }?>
					</select></td>
				<td colspan="2">ค่าใช้จ่าย    <input type="text" name="addcost" style="width:100px;">  บาท</td>
				<td colspan="2">วิทยากร   <input type="text" name="addtrainer" style="width:200px;"></td>
				
			</tr>
			<tr><td colspan="1">หมายเหตุ</td><td colspan="7"><input type="text" name="addremark" style="width:611px;"></td></tr>
	
		
		</table>
		
		<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>บันทึก</button>
		<a href="home.php" class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>ยกเลิก</a>
		</form>
</body>
</html>
 
 
train_save.php Code (PHP) 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?PHP
include("connectdb.php");
$strSQL = "INSERT INTO tbtraining ";
$strSQL .="(trainingdate,topicsid,traininghours,placeid,trainingexpense,trainername,trainingremark,trainingcode)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["addtraindate"]."','".$_POST["addcourse"]."','".$_POST["addhrs"]."','".$_POST["addplace"]."' ";
$strSQL .=",'".$_POST["addcost"]."','".$_POST["addtrainer"]."','".$_POST["addremark"]."','".$POST["addtrcode"]."') ";
$objQuery = sqlsrv_query($conn,$strSQL);
if($objQuery){
	header("location:home.php");
}
else
{
	echo " Error Save [".$strSQL."] ";
}
sqlsrv_close($conn);
?>
                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2017-11-27 16:36:25              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-11-27 16:09:03 | 
                        By :
                            bonusxi | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ได้แล้วค่ะ ผิดพลาดเอง ขอบคุณมากค่ะ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-11-27 16:49:09 | 
                        By :
                            bonusxi | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                                          
               
               | 
             
            
              
			  			  
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-11-27 16:59:29 | 
                        By :
                            mr.win | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |