  | 
              
	              
	                
  
    
	 
        สอบถามเกี่ยวกับ mysql ครับ insert แล้วค่าที่ insert ไม่เข้าครับขึ้นแต่พวก แถวครับ     | 
   
  
    |   | 
   
 
 
 
	
		
			  | 
	   | 
	    | 
		
			  | 
	 
	
		
			  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                ตอนนี้ติดปัญหาตรง Select checkbox พอกดซัมมิท แล้วขึ้นตามรูปอะครับอยากทราบว่าโค้ดผิดตรงไหนครับ 
  
 
หน้า checkbok ครับ 
Code (PHP) 
<?php require_once('Connections/myconnect.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
mysql_select_db($database_myconnect, $myconnect);
$query_showindex = "SELECT * FROM tbl_product ORDER BY p_id ASC";
$showindex = mysql_query($query_showindex, $myconnect) or die(mysql_error());
$row_showindex = mysql_fetch_assoc($showindex);
$totalRows_showindex = mysql_num_rows($showindex);
$bmiid = "-1";
if (isset($_GET['BMI_id'])) {
  $bmiid = $_GET['BMI_id'];}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="food_insert.php">
<table border="1" align="center" cellpadding="20">
  <tr>
    <center><td>p_id</td>
    <td>ชื่ออาหาร</td>
    <td>รายละเอียด</td>
    <td>แคลอรี่</td>
    <td>รูปภาพ</td>
    <td>วันเวลา</td>
    <td>ลบข้อมูล</td>
    <td>แก้ไข</td></center>
  </tr> 
  <?php $x = 1; do { ?>
    <tr>
      <td><?php echo $row_showindex['p_id']; ?>
       
          <input type="checkbox" value = "<?php echo $p_id; ?>" name="check<?php echo $x; ?>" id="idmenu" />
          <input name="p_id<?php echo $x; ?>" type="hidden" value="<?php echo $row_showindex['p_id']; ?>" />
          <input name="bmi_id<?php echo $x; ?>" type="hidden" value="<?php echo $bmiid; ?>" />
          <input name="p_name<?php echo $x; ?>" type="hidden" value="<?php echo $row_showindex['p_name']; ?> " />
      </td>
      <td><?php echo $row_showindex['p_name']; ?></td>
      <td><?php echo $row_showindex['p_detail']; ?></td>
      <td><?php echo $row_showindex['p_price']; ?></td>
      <td><img src="img/<?php echo $row_showindex['p_img']; ?>" width="100" /></td>
      <td><?php echo $row_showindex['p_save']; ?></td>
      <td><div align="center"><a href="delete.php?p_id=<?php echo $row_showindex['p_id']; ?>">ลบ</a></div></td>
      <td><a href="edit1.php?p_id=<?php echo $row_showindex['p_id']; ?>">แก้ไข</a></td>
    </tr>
    <?php $x++; } while ($row_showindex = mysql_fetch_assoc($showindex)); ?>
    
   
</table>
<center>
<input name="x" type="hidden" value="<?php echo $x-1 ?>" />
<input name="" type="submit" /></center>
 </form>
<center>
  <a href="add_product.php">เพิ่มอาหาร</a>
</center>
</body>
</html>
<?php
mysql_free_result($showindex);
?>
 
 
หน้าส่งค่าไปยังดาต้าเบส 
Code (PHP) 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
require_once('connect.php');
 $sql = "INSERT INTO  food_suggestion
					(BMI_id	,
					food_id	, 
					p_name
					) 
					VALUES
					('$bmi',
					 '$pid',
					 '$pname')";
		
		$result = mysql_db_query($database_condb, $sql) or die ("Error in query: $sql " . mysql_error());
	mysql_close();
	if($result){
   
			echo "<script type='text/javascript'>";
			echo  "alert('เพิ่มเรียบร้อย');";
			echo "window.location='showindex1.php';";
			echo "</script>";
	  }
	  else{
		    echo "<script type='text/javascript'>";
			echo  "alert('error');";
				echo "window.location='showindex1.php';";
			echo "</script>";
	  }
	
?>
<body>
</body>
</html>
 
 
  Tag : PHP, MySQL, HTML, HTML5, jQuery, Appserv               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2019-04-04 01:03:46 | 
                      By :
                          Nirawit | 
                      View :
                          769 | 
                      Reply :
                          7 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  | 
	 
	
		
			  | 
		  | 
		
			  | 
		
			  | 
	 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
<?php
require_once('connect.php');
header('Content-Type: text/html; charset=utf-8');
$sql = "INSERT INTO  food_suggestion	(BMI_id,	food_id, p_name) VALUES ('$bmi', '$pid', '$pname')";
mysql_db_query($database_condb, $sql) or die ("Error in query: $sql " . mysql_error());
echo $sql,'<br>'; // เอาออกถ้าตรวจสอบเรียบร้อย
?>
<script type='text/javascript'>
	alert('<?=(mysql_affected_rows() ? 'เพิ่มเรียบร้อย' : 'error')?>');
	window.location='showindex1.php';
</script>
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-04-04 06:11:29 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 echo $sql,'<br>'; // เอาออกถ้าตรวจสอบเรียบร้อย 
ตรงนี้ มันแสดงอะไรออกมาครับ ผมยากเห็นตรงนี้                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-04-04 10:35:20 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ถ้ามันไม่แสดงอะไรเลย ผมว่าไปเริ่มต้น ศึกษาพื้นฐานเริ่มต้นใหม่เลยครับ 
 
https://www.thaicreate.com/php.html 
 
เริ่มต้นจากตัวอย่าง เบื้องต้นก่อน การส่งค่า post get  
รูปแบบการใช้ไวยกรณ์ต่างๆ เขียนตามตัวอย่างให้ทำงานได้ก่อน  
 
เพราะตัวอย่างที่ผมเขียนให้ ก็ใช้โครงสร้างของ จขกท มาเพิ่มส่วนที่ต้องตรวจสอบ 
โดยคิดว่า มันเป็นแค่ส่วนหนึ่งของไฟล์ที่จขกท ตัดมาให้ดู แต่ตอนนี้คิดว่ามันเป็นทั้งหมด 
เพราะ ถ้ามันไม่มีอะไรโชว์ มันก็เออเร่อร์ มาตั้งแต่ตัวแปรที่ไม่ได้มีการกำหนดไว้                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2019-04-04 17:19:46 | 
                        By :
                            Chaidhanan | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |