Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ติดปัญหา Error โค้ด เกี่ยวกับการ Import xml to sql sever รบกวนช่วยดูให้หน่อยได้มั๊ยคะ



 

ติดปัญหา Error โค้ด เกี่ยวกับการ Import xml to sql sever รบกวนช่วยดูให้หน่อยได้มั๊ยคะ

 



Topic : 123332



โพสกระทู้ ( 36 )
บทความ ( 0 )



สถานะออฟไลน์




เจอปัญหาในการ import ไฟล์ xml เพื่อเพิ่มข้อมูลในฐานข้อมูล โดยติดปัญหา Error


Error
PHP Strict Standards: Non-static method DOMDocument::load() should not be called statically in C:\inetpub\wwwroot\testphp\import_form.php on line 21
PHP Warning: move_uploaded_file(uploads/test.xml): failed to open stream: No such file or directory in C:\inetpub\wwwroot\testphp\import_form.php on line 87
PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\phpA392.tmp' to 'uploads/test.xml' in C:\inetpub\wwwroot\testphp\import_form.php on line 87




รบกวนช่วยหน่อยนะคะ จากโค้ดนี้ค่ะ

Code (PHP)
<?php
	
session_start();
$error=0;
include "connect.php";
$num_insert=0;
if(isset($_POST["SubmitForm"]))
{//start
	$filename=strtolower($_FILES['file']['name']);
	$find=strpos($filename,'xml');
	$order=0;
		if($find===false)
		{
			echo "<b><font color='#ff0000'>กรุณา upload file .xml เท่านั้น </font></b>";
		}else
		{//
		if ( $_FILES['file']['error'] )
		{ 
			die("upload error "); 
		} 	
		$dom    =    DOMDocument::load( $_FILES['file']['tmp_name'] );
		$rows    =   $dom->getElementsByTagName('Row'); 
		$row    =    0;
	 
//echo 'numfound='.$numfound.'</br/>';
		foreach ($rows as $temp)
		{ 
			$col = 0; 
		  if($row==0)
		   { 
			 $row++; continue; 
		   } 
			$cells    = $temp->getElementsByTagName('Cell'); 
			foreach( $cells as $cell )
			 { 
				 if($col==0) $entity = $cell->nodeValue; 
				 if($col==1) $install_date = $cell->nodeValue;
				 if($col==2) $contactno=$cell->nodeValue;
				 if($col==3) $customername=$cell->nodeValue;
				 if($col==4) $address=$cell->nodeValue;
				 if($col==5) $province=$cell->nodeValue;
				 if($col==6) $model=$cell->nodeValue;
				 if($col==7) $serial=$cell->nodeValue;
				 if($col==8) $saleentity=$cell->nodeValue;
				 if($col==9) $from_sale_code=$cell->nodeValue;
				 if($col==10) $from_sale_name=$cell->nodeValue;
				 if($col==11) $remark=$cell->nodeValue;
				 
				 
				 
				 
				 $col++; 
			} 
		if($entity!='')
		{//if start entity
			$sql_find="select * from rental_info_temp where serial='".$serial."' ";
			$result_find=sqlsrv_query($con,$sql_find);
			$num_found=sqlsrv_has_rows($result_find);
			if($num_found==0||$num_found=="")
			{
				
				$order++;
				$importcode=date('YmdHsA').$order;
				if($remark=="")
				{
					$remark="-";
				}
				$sql="insert into rental_info_temp values('".$entity."',N'".$customername."',N'".$address."',N'".$province."','".$model."','".$serial."','".$install_date."','".$saleentity."',N'".$from_sale_code."',N'".$from_sale_name."','".$contactno."',N'".$remark."','".$importcode."')";
				$result_query=sqlsrv_query($con,$sql);
				//echo "yes sn=".$serial."=".$sql."</br>";
				if(!$result_query)
				{
					$error+=1;
				}else{
					$num_insert+=1;
				}
			}else {//end if num_found
			
				$sql_update="update rental_info_temp set entity='".$entity."',cusname=N'".$customername."',address=N'".$address."',province=N'".$province."',model='".$model."',installdate='".$install_date."',saleentity='".$saleentity."',fromsalecode=N'".$from_sale_code."',fromsalename=N'".$from_sale_name."',contactno='".$contactno."' where serial='".$serial."'";
				$result_query=sqlsrv_query($con,$sql_update);
			}//end else num found
		 }//end if entity
	 $row++;  
	  } //end foreach
	   
	  $_SESSION["insert"]=$num_insert;
	  move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES["file"]['name']);
	  header('Location:http://uccinfo:85/rental/import.php');
	 }//end if xml file
}//end if SubmitForm
?>
<!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" />
<link type="text/css" href="css/default.css" rel="stylesheet"/>
<title>Import Excel File</title>
<script language="javascript" type="text/javascript">
function openDocDetail(url,width,height)
{
		var windowWidth=width;
		var windowHeight=height;
		var centerWidth = (window.screen.width - windowWidth) / 2;
   		var centerHeight = (window.screen.height - windowHeight) / 2;
        OpenWindow=window.open(url, "","menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,resizable=no,width="+windowWidth+",height="+windowHeight+",top="+centerHeight+",left="+centerWidth);
}
</script>
</head>

<body>
<p><h2>Import ข้อมูลติดตั้งเครื่องเช่า</h2></p>
<form enctype="multipart/form-data" action="import_form.php" method="post"> 
<table width="95%" border="0" align="center" style="border-collapse:" >
  <tr>
    <td width="23%">เลือกไฟล์ (นามสกุล .xml) เท่านั้น</td>
    <td><input type="file" name="file" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><label>
      <input type="submit" name="SubmitForm" value="Submit" />
      <input type="submit" name="Cancel" value="Cancel" />
    </label></td>
  </tr>
</table>
</form>
<ul id="menu">
 <li><a href="#" onclick="javascript:openDocDetail('save_xml.php','1000','500');" class="txtlink">วิธี save file .xml</a></li>
 <li><a href="upload_format.xls" class="txtlink">รูปแบบไฟล์สำหรับ import</a>
 <li><a href="#" onclick="javascript:openDocDetail('all_upload.php','1100','500');" class="txtlink">ข้อมูลที่  import แล้ว</a></li>
 <li><a href="manual/Manual_import.pdf" class="txtlink" target="_blank">คู่มือการ import</a></li>
<li><a href="http://uccinfo/request_install/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={EFC33510-6AA7-4842-99A2-C682CB3E983B}&View={8D7AB465-BE40-4E14-962C-BED9B5CAD2D3}&CacheControl=1&RootFolder=" onclick="GoToLinks(this) ;return false;" target="_self">Export</a></li>
</ul>
</body>
</html>




Tag : PHP, Ms SQL Server 2012







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-06-14 11:47:58 By : Phatsanan View : 1140 Reply : 6
 

 

No. 1



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
แก้เป็น
$xml_handle = new DOMDocument();
$dom = $xml_handle->load( $_FILES['file']['tmp_name'] );
http://php.net/manual/en/domdocument.load.php

ส่วน
move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES["file"]['name']);

มี folder สีแดงหรือเปล่า หรือ มี สิทธิ์ สร้างไฟล์ หรือไม่






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-06-14 12:32:17 By : Chaidhanan
 


 

No. 2



โพสกระทู้ ( 36 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : Chaidhanan เมื่อวันที่ 2016-06-14 12:32:17
รายละเอียดของการตอบ ::
ขอบคุณ คุณ Chaidhanan Error เก่าหายไปแล้วค่ะ แต่มี Error ใหม่มาแทนค่ะ
รบกวนช้วยอีกครั้งได้ไหมค่ะ

PHP Fatal error: Call to a member function getElementsByTagName() on a non-object in C:\inetpub\wwwroot\testphp\import_form.php on line 26

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-06-14 13:23:55 By : Phatsanan
 

 

No. 3



โพสกระทู้ ( 9,559 )
บทความ ( 2 )



สถานะออฟไลน์


$cells = $temp->getElementsByTagName('Cell');

ก่อนที่จะ เซทค่าลงตัวแปร เราควร เช็ค $temp ก่อนว่า มี element ลูก อยู่ด้วยไหม
Code (PHP)
if( $temp.count()>0){
   $cells = $temp->getElementsByTagName('Cell'); 


ซึ่งควรทำกับทุำลำดับชั้น

ทดสอบว่า ค่าที่อ่านมาถูกต้องไหม ให้ใช้
print_r($dom); แล้วอ่านด้วยตาว่า สิ่งที่ได้มาเป็นอะไร มีลำดับชั้นอย่างไร

ปล. ผมไม่เคยใช้ dom นะครับ แค่เคยอ่านจาก document เฉยๆ
ไม่แน่ใจว่า print_r($dom); จะใช้ได้ไหม แต่คิดว่าควรจะใช้ได้ ถ้าไม่ได้ก็เอามาถามใหม่นะครับ


ประวัติการแก้ไข
2016-06-14 13:39:50
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-06-14 13:37:52 By : Chaidhanan
 


 

No. 4



โพสกระทู้ ( 36 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : Chaidhanan เมื่อวันที่ 2016-06-14 13:37:52
รายละเอียดของการตอบ ::
ขอบคุณ คุณ Chaidhanan จะลองทำดูค่ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-06-14 14:13:51 By : Phatsanan
 


 

No. 5



โพสกระทู้ ( 36 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : Chaidhanan เมื่อวันที่ 2016-06-14 13:37:52
รายละเอียดของการตอบ ::
ตอนนี้อ่านไฟล์ xmlได้แล้วค่ะ แต่ข้อมูลยังไม่เข้าไปใน sql server ค่ะ มี error คือ

Error
PHP Warning: move_uploaded_file(uploads/Book1.xml): failed to open stream: Permission denied in C:\inetpub\wwwroot\testphp\import_form.php on line 90
PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php89F6.tmp' to 'uploads/Book1.xml' in C:\inetpub\wwwroot\testphp\import_form.php on line 90




รอบกวนช้วยด้วยค่ะ


โค้ด php ค่ะ


Code (PHP)
<?php
	
session_start();
$error=0;
include "connect.php";
$num_insert=0;
if(isset($_POST["SubmitForm"]))
{//start
	$filename=strtolower($_FILES['file']['name']);
	$find=strpos($filename,'xml');
	$order=0;
		if($find===false)
		{
			echo "<b><font color='#ff0000'>กรุณา upload file .xml เท่านั้น </font></b>";
		}else
		{//
		if ( $_FILES['file']['error'] )
		{
			die("upload error "); 
		} 	
		
		$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
		$rows    =   $dom->getElementsByTagName('Row'); 
		$row    =    0;
		print_r($dom);
		
	 
//echo 'numfound='.$numfound.'</br/>';
		foreach ($rows as $temp)
		{ 
			$col = 0; 
		  if($row==0)
		   { 
			 $row++; continue; 
		   } 
			$cells    = $temp->getElementsByTagName('Cell'); 
			foreach( $cells as $cell )
			 { 
				 if($col==0) $entity = $cell->nodeValue; 
				 if($col==1) $install_date = $cell->nodeValue;
				 if($col==2) $contactno = $cell->nodeValue;
				 if($col==3) $customername = $cell->nodeValue;
				 if($col==4) $address = $cell->nodeValue;
				 if($col==5) $province = $cell->nodeValue;
				 if($col==6) $model = $cell->nodeValue;
				 if($col==7) $serial = $cell->nodeValue;
				 if($col==8) $saleentity = $cell->nodeValue;
				 if($col==9) $from_sale_code = $cell->nodeValue;
				 if($col==10) $from_sale_name = $cell->nodeValue;
				 if($col==11) $remark = $cell->nodeValue;
				 
				 
				 
				 
				 $col++; 
			} 
		if($entity!='')
		{//if start entity
			$sql_find="select * from rental_info_temp where serial='".$serial."' ";
			$result_find=sqlsrv_query($con,$sql_find);
			$num_found=sqlsrv_has_rows($result_find);
			if($num_found==0||$num_found=="")
			{
				
				$order++;
				$importcode=date('YmdHsA').$order;
				if($remark=="")
				{
					$remark="-";
				}
				$sql="insert into rental_info_temp values('".$entity."',N'".$customername."',N'".$address."',N'".$province."','".$model."','".$serial."','".$install_date."','".$saleentity."',N'".$from_sale_code."',N'".$from_sale_name."','".$contactno."',N'".$remark."','".$importcode."')";
				$result_query=sqlsrv_query($con,$sql);
				//echo "yes sn=".$serial."=".$sql."</br>";
				if(!$result_query)
				{
					$error+=1;
				}else{
					$num_insert+=1;
				}
			}else {//end if num_found
			
				$sql_update="update rental_info_temp set entity='".$entity."',customername=N'".$customername."',address=N'".$address."',province=N'".$province."',model='".$model."',install_date='".$install_date."',saleentity='".$saleentity."',from_sale_code=N'".$from_sale_code."',from_sale_name=N'".$from_sale_name."',contactno='".$contactno."' where serial='".$serial."'";
				$result_query=sqlsrv_query($con,$sql_update);
			}//end else num found
		 }//end if entity
	 $row++;  
	  } //end foreach  
	   
	  $_SESSION["insert"]=$num_insert;
	  move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES["file"]['name']);
	  header('Location:http://uccinfo:85/rental/import.php');
	 }//end if xml file
}//end if SubmitForm   
?>
<!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/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" href="css/default.css" rel="stylesheet"/>
<title>Import Excel File</title>
<script language="javascript" type="text/javascript">
function openDocDetail(url,width,height)
{
		var windowWidth=width;
		var windowHeight=height;
		var centerWidth = (window.screen.width - windowWidth) / 2;
   		var centerHeight = (window.screen.height - windowHeight) / 2;
        OpenWindow=window.open(url, "","menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,resizable=no,width="+windowWidth+",height="+windowHeight+",top="+centerHeight+",left="+centerWidth);
}
</script>
</head>

<body>
<p><h2>Import ข้อมูลติดตั้งเครื่องเช่า</h2></p>
<form enctype="multipart/form-data" action="import_form.php" method="post"> 
<table width="95%" border="0" align="center" style="border-collapse:" >
  <tr>
    <td width="23%">เลือกไฟล์ (นามสกุล .xml) เท่านั้น</td>
    <td><input type="file" name="file" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><label>
      <input type="submit" name="SubmitForm" value="Submit" />
      <input type="submit" name="Cancel" value="Cancel" />
    </label></td>
  </tr>
</table>
</form>
<ul id="menu">
 <li><a href="#" onclick="javascript:openDocDetail('save_xml.php','1000','500');" class="txtlink">วิธี save file .xml</a></li>
 <li><a href="upload_format.xls" class="txtlink">รูปแบบไฟล์สำหรับ import</a>
 <li><a href="#" onclick="javascript:openDocDetail('all_upload.php','1100','500');" class="txtlink">ข้อมูลที่  import แล้ว</a></li>
 <li><a href="manual/Manual_import.pdf" class="txtlink" target="_blank">คู่มือการ import</a></li>
<li><a href="http://uccinfo/request_install/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={EFC33510-6AA7-4842-99A2-C682CB3E983B}&View={8D7AB465-BE40-4E14-962C-BED9B5CAD2D3}&CacheControl=1&RootFolder=" onclick="GoToLinks(this) ;return false;" target="_self">Export</a></li>
</ul>
</body>
</html>





แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-06-23 11:27:33 By : Phatsanan
 


 

No. 6



โพสกระทู้ ( 36 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : Chaidhanan เมื่อวันที่ 2016-06-14 12:32:17
รายละเอียดของการตอบ ::
อ่อ error เพราะ ไม่ได้กำหนดสิทธิ์สร้างไฟล์นี้เอง ขอบคุณ คุณ Chaidhanan มากเลยค่ะ ตอนนี้ได้แล้วค่ะ ขอบคุณมากๆค่ะ (พอดีมือใหม่อ่ะค่ะ ^^)

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-06-24 15:49:45 By : Phatsanan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ติดปัญหา Error โค้ด เกี่ยวกับการ Import xml to sql sever รบกวนช่วยดูให้หน่อยได้มั๊ยคะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่