|  | 
	                
  
    | 
	 
        php mysql ทำไม insert ข้อมูลไม่ได้ครับ ทั้งที่คำสั่ง query ก็เหมือนกัน     |  
    |  |  
 
	
		|  |  |  |  |  
		|  |  | 
          
            | 1.อันนี้เพิ่มข้อมูลฟิลเดียว ได้ครับ 
 Code (PHP)
 
 $sql="insert into type_news values(null,'$news_name')";
$result=mysql_db_query($dbname,$sql);
 
 2.แต่พอเพิ่มข้อมูล หลายฟิล ทำไมเพิ่มไม่ได้ครับ
 
 Code (PHP)
 
 $sql_news="INSERT INTO news VALUES('','$news_title','$news_title2','$news_detail','','$news_type','$news_date','','','$news_postid')";
$result=mysql_db_query($dbname,$sql_news);
 **** ทดสอบกับ โปรแกรมappserv ได้ / ทดสอบกับโฮสต์จริงได้
 
 แต่ทำไมมีอยู่อีกโฮสต์หนึ่งกลับทำไม่ได้อย่างที่บอก เป็นที่เวอร์ชันของ php ที่รองรับหรือเปล่า แต่แล้วทำไม insert ตามข้อ 1ได้ พอ insert ตามข้อ 2 กลับไม่ได้
 
 
 
 Tag : - - - -
 
 |  
            |  |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2012-10-31 16:55:12 | By :
                          kim_cmu | View :
                          2420 | Reply :
                          5 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |  
		|  |  |  |  |  
  
    | 
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองเพิ่ม or die(mysql_error()) เอา error มาดูครับ 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-10-31 20:37:33 | By :
                            mr.win |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ลองเปลี่ยนเป็นใช้ Complete Insert ดูครับ 
 
 เช่น
 
 
INSERT INTO `users` 
(`usr_uid`, `usr_active`, `usr_fname`, `usr_lname`, `uer_address`) 
VALUES 
('', 1, 'Name', 'Last Name', 'Bangkok');
 
 ไม่ก็ลองเช็คค่า Null ดูนะครับ สำหรับ AI
 
 |  
              | 
 ประวัติการแก้ไข
 2012-11-01 02:46:06
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-11-01 02:44:41 | By :
                            p_latplee |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | สรุปคือ สามารถติดต่อฐานข้อมูลได้ 
 แต่ปัญหาอยู่ที่วรรคนี้
 Code (PHP)
 
 if (!$result) {
echo "<script>alert('ไม่สามารถเพิ่มข่าวได้');window.location='?name=admin/news&file=admin_main_new';</script>";
 }
 code ทั้งหมด
 
 Code (PHP)
 
 <?
$news_title=$_POST['news_title'];
$news_title2=$_POST['news_title2'];
$news_detail=$_POST['news_detail'];
$news_type=$_POST['news_type'];
$news_postid=$_POST['news_postid'];
$photo=$_FILES['photo']['tmp_name'];
$photo_name=$_FILES['photo']['name'];
$photo_size=$_FILES['photo']['size'];
$photo_type=$_FILES['photo']['type'];
$file=$_FILES['file']['tmp_name'];
$file_name=$_FILES['file']['name'];
$file_size=$_FILES['file']['size'];
$file_type=$_FILES['file']['type'];
if ($photo!= "") // ตรวจสอบว่ามีไฟล์ส่งมาหรือไม่
{ if(strchr($photo_name,".")==".JPG" || strchr($photo_name,".")==".jpg" || strchr($photo_name,".")==".GIF" || strchr($photo_name,".")==".gift" || strchr($photo_name,".")==".png") {
     } else {
echo "<script>alert('กรุณาเลือกภาพ .jpg .jpeg .png .gif เท่านั้น');history.back();</script>";
exit();
     }
}
	// ตรวจสอบขนารูปภาพที่อัพโหลด
if ($photo_size>204800) {
			echo "<script>alert('รูปภาพของท่านมีขนาดเกิน 200 kb กรุณากลับไปกรอกข้อมูลอีกทีนะครับ');history.back();</script>";
			exit();
}
	// ตรวจสอบขนาดไฟล์ที่อัพโหลด
if ($file_size>10485760) {
echo "<script>alert('ไฟล์ของท่านมีขนาดเกิน 10 Mb ครับ กรุณากลับไปกรอกข้อมูลอีกทีนะครับ');history.back();</script>";
exit();
}
if ($news_title=="" or $news_detail=="" or $news_type=="0") {
echo "<script>alert('กรุณากรอกข้อมูลให้ ครบนะครับ');history.back();</script>";
exit();
}
$news_date=time();
$sql_news="INSERT INTO `news` 
(`news_id`, `news_title`, `news_title2`, `news_detail`, `type_news_id`, `news_date`, `news_postid`) 
VALUES('','$news_title','$news_title2','$news_detail','$news_type','$news_date','$news_postid')";
$result=mysql_db_query($dbname,$sql_news);
// Call Function
//addGDLogoLicense("$photo","modules/photo/logo.png");
$ext = strtolower(end(explode('.', $photo_name)));
if ($ext == "jpg" or $ext == "jpeg" or $ext=="gif" or $ext=="png") {
		
		$sql1="select max(news_id) from news";
		$result1=mysql_db_query($dbname,$sql1);
		$r=mysql_fetch_array($result1);
		$id_max=$r[0];
		$filename=$id_max.".".$ext;
		copy($photo,"modules/news/photo/$filename");
		$sql="update news set news_img='$filename' where news_id='$id_max' ";
		mysql_db_query($dbname,$sql);
}
$ext1 = strtolower(end(explode('.', $file_name)));
if ($ext1 == "zip" or $ext1 == "rar" or $ext1=="doc" or $ext1=="docx" or $ext1=="pdf") {
	$sql2="select max(news_id) from news";
	$result2=mysql_db_query($dbname,$sql2);
	$r=mysql_fetch_array($result2);
	$id_max1=$r[0];
	$filename=$id_max1.".".$ext1;
	copy($file,"modules/news/file/$filename");
	$sql3="update news set news_dowload='$filename' where news_id='$id_max1' ";
	mysql_db_query($dbname,$sql3);
}
if (!$result) {
echo "<script>alert('ไม่สามารถเพิ่มข่าวได้');window.location='?name=admin/news&file=admin_main_new';</script>";
 } else { 
echo "<script>alert('เพิ่มข่าวสารเรียบร้อยแล้ว');window.location='?name=admin/news&file=admin_main_new';</script>";
 }
 mysql_close();
?>
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-11-01 10:22:49 | By :
                            kim_cmu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ได้แล้วครับตามลิ้งนี้ครับ 
 http://ping2p.blogspot.com/2008/09/1366-incorrect-integer-value-for-column.html
 
 เพิ่ม insert  into เปลี่ยนเป็น insert ignore into
 
 |  
              | 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-11-01 14:35:06 | By :
                            kim_cmu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  
 
        
          |  |  |  |  |  
          |  |  | 
            
              | ตอนเพิ่มได้เพราะ ตรงค่าว่าง ใช้ null จึงไม่ต้องมี ignore แต่ตอนที่ ใส่ค่าของฟิลเป็นค่าว่าง '' จะต้องใช้ ignore ร่วมด้วย ไม่ว่าฟิลที่เป็นค่าว่าง เราจะใส่จะเป็น null หรือจะเป็น '' ก็ไม่มีปัญหา
 
 |  
              | 
 ประวัติการแก้ไข
 2012-11-01 14:56:50
 
                
                  |  |  |  |  
                  |  | 
                      
                        | Date :
                            2012-11-01 14:39:50 | By :
                            kim_cmu |  |  |  
                  |  |  |  |  |  |  |  
          |  |  |  |  |  |  |