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,038

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


[PHP] ติดปัญหา 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)
001.<?php
002.     
003.session_start();
004.$error=0;
005.include "connect.php";
006.$num_insert=0;
007.if(isset($_POST["SubmitForm"]))
008.{//start
009.    $filename=strtolower($_FILES['file']['name']);
010.    $find=strpos($filename,'xml');
011.    $order=0;
012.        if($find===false)
013.        {
014.            echo "<b><font color='#ff0000'>กรุณา upload file .xml เท่านั้น </font></b>";
015.        }else
016.        {//
017.        if ( $_FILES['file']['error'] )
018.        {
019.            die("upload error ");
020.        }  
021.        $dom    =    DOMDocument::load( $_FILES['file']['tmp_name'] );
022.        $rows    =   $dom->getElementsByTagName('Row');
023.        $row    =    0;
024.      
025.//echo 'numfound='.$numfound.'</br/>';
026.        foreach ($rows as $temp)
027.        {
028.            $col = 0;
029.          if($row==0)
030.           {
031.             $row++; continue;
032.           }
033.            $cells    = $temp->getElementsByTagName('Cell');
034.            foreach( $cells as $cell )
035.             {
036.                 if($col==0) $entity = $cell->nodeValue;
037.                 if($col==1) $install_date = $cell->nodeValue;
038.                 if($col==2) $contactno=$cell->nodeValue;
039.                 if($col==3) $customername=$cell->nodeValue;
040.                 if($col==4) $address=$cell->nodeValue;
041.                 if($col==5) $province=$cell->nodeValue;
042.                 if($col==6) $model=$cell->nodeValue;
043.                 if($col==7) $serial=$cell->nodeValue;
044.                 if($col==8) $saleentity=$cell->nodeValue;
045.                 if($col==9) $from_sale_code=$cell->nodeValue;
046.                 if($col==10) $from_sale_name=$cell->nodeValue;
047.                 if($col==11) $remark=$cell->nodeValue;
048.                  
049.                  
050.                  
051.                  
052.                 $col++;
053.            }
054.        if($entity!='')
055.        {//if start entity
056.            $sql_find="select * from rental_info_temp where serial='".$serial."' ";
057.            $result_find=sqlsrv_query($con,$sql_find);
058.            $num_found=sqlsrv_has_rows($result_find);
059.            if($num_found==0||$num_found=="")
060.            {
061.                 
062.                $order++;
063.                $importcode=date('YmdHsA').$order;
064.                if($remark=="")
065.                {
066.                    $remark="-";
067.                }
068.                $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."')";
069.                $result_query=sqlsrv_query($con,$sql);
070.                //echo "yes sn=".$serial."=".$sql."</br>";
071.                if(!$result_query)
072.                {
073.                    $error+=1;
074.                }else{
075.                    $num_insert+=1;
076.                }
077.            }else {//end if num_found
078.             
079.                $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."'";
080.                $result_query=sqlsrv_query($con,$sql_update);
081.            }//end else num found
082.         }//end if entity
083.     $row++; 
084.      } //end foreach
085.        
086.      $_SESSION["insert"]=$num_insert;
087.      move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES["file"]['name']);
088.      header('Location:http://uccinfo:85/rental/import.php');
089.     }//end if xml file
090.}//end if SubmitForm
091.?>
092.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
093.<html xmlns="http://www.w3.org/1999/xhtml">
094.<head>
095.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
096.<link type="text/css" href="css/default.css" rel="stylesheet"/>
097.<title>Import Excel File</title>
098.<script language="javascript" type="text/javascript">
099.function openDocDetail(url,width,height)
100.{
101.        var windowWidth=width;
102.        var windowHeight=height;
103.        var centerWidth = (window.screen.width - windowWidth) / 2;
104.        var centerHeight = (window.screen.height - windowHeight) / 2;
105.        OpenWindow=window.open(url, "","menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,resizable=no,width="+windowWidth+",height="+windowHeight+",top="+centerHeight+",left="+centerWidth);
106.}
107.</script>
108.</head>
109. 
110.<body>
111.<p><h2>Import ข้อมูลติดตั้งเครื่องเช่า</h2></p>
112.<form enctype="multipart/form-data" action="import_form.php" method="post">
113.<table width="95%" border="0" align="center" style="border-collapse:" >
114.  <tr>
115.    <td width="23%">เลือกไฟล์ (นามสกุล .xml) เท่านั้น</td>
116.    <td><input type="file" name="file" /></td>
117.  </tr>
118.  <tr>
119.    <td>&nbsp;</td>
120.    <td>&nbsp;</td>
121.  </tr>
122.  <tr>
123.    <td>&nbsp;</td>
124.    <td><label>
125.      <input type="submit" name="SubmitForm" value="Submit" />
126.      <input type="submit" name="Cancel" value="Cancel" />
127.    </label></td>
128.  </tr>
129.</table>
130.</form>
131.<ul id="menu">
132. <li><a href="#" onclick="javascript:openDocDetail('save_xml.php','1000','500');" class="txtlink">วิธี save file .xml</a></li>
133. <li><a href="upload_format.xls" class="txtlink">รูปแบบไฟล์สำหรับ import</a>
134. <li><a href="#" onclick="javascript:openDocDetail('all_upload.php','1100','500');" class="txtlink">ข้อมูลที่  import แล้ว</a></li>
135. <li><a href="manual/Manual_import.pdf" class="txtlink" target="_blank">คู่มือการ import</a></li>
136.<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>
137.</ul>
138.</body>
139.</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 : 1216 Reply : 6
 

 

No. 1



โพสกระทู้ ( 9,590 )
บทความ ( 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,590 )
บทความ ( 2 )



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


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

ก่อนที่จะ เซทค่าลงตัวแปร เราควร เช็ค $temp ก่อนว่า มี element ลูก อยู่ด้วยไหม
Code (PHP)
1.if( $temp.count()>0){
2.   $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)
001.<?php
002.     
003.session_start();
004.$error=0;
005.include "connect.php";
006.$num_insert=0;
007.if(isset($_POST["SubmitForm"]))
008.{//start
009.    $filename=strtolower($_FILES['file']['name']);
010.    $find=strpos($filename,'xml');
011.    $order=0;
012.        if($find===false)
013.        {
014.            echo "<b><font color='#ff0000'>กรุณา upload file .xml เท่านั้น </font></b>";
015.        }else
016.        {//
017.        if ( $_FILES['file']['error'] )
018.        {
019.            die("upload error ");
020.        }  
021.         
022.        $dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
023.        $rows    =   $dom->getElementsByTagName('Row');
024.        $row    =    0;
025.        print_r($dom);
026.         
027.      
028.//echo 'numfound='.$numfound.'</br/>';
029.        foreach ($rows as $temp)
030.        {
031.            $col = 0;
032.          if($row==0)
033.           {
034.             $row++; continue;
035.           }
036.            $cells    = $temp->getElementsByTagName('Cell');
037.            foreach( $cells as $cell )
038.             {
039.                 if($col==0) $entity = $cell->nodeValue;
040.                 if($col==1) $install_date = $cell->nodeValue;
041.                 if($col==2) $contactno = $cell->nodeValue;
042.                 if($col==3) $customername = $cell->nodeValue;
043.                 if($col==4) $address = $cell->nodeValue;
044.                 if($col==5) $province = $cell->nodeValue;
045.                 if($col==6) $model = $cell->nodeValue;
046.                 if($col==7) $serial = $cell->nodeValue;
047.                 if($col==8) $saleentity = $cell->nodeValue;
048.                 if($col==9) $from_sale_code = $cell->nodeValue;
049.                 if($col==10) $from_sale_name = $cell->nodeValue;
050.                 if($col==11) $remark = $cell->nodeValue;
051.                  
052.                  
053.                  
054.                  
055.                 $col++;
056.            }
057.        if($entity!='')
058.        {//if start entity
059.            $sql_find="select * from rental_info_temp where serial='".$serial."' ";
060.            $result_find=sqlsrv_query($con,$sql_find);
061.            $num_found=sqlsrv_has_rows($result_find);
062.            if($num_found==0||$num_found=="")
063.            {
064.                 
065.                $order++;
066.                $importcode=date('YmdHsA').$order;
067.                if($remark=="")
068.                {
069.                    $remark="-";
070.                }
071.                $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."')";
072.                $result_query=sqlsrv_query($con,$sql);
073.                //echo "yes sn=".$serial."=".$sql."</br>";
074.                if(!$result_query)
075.                {
076.                    $error+=1;
077.                }else{
078.                    $num_insert+=1;
079.                }
080.            }else {//end if num_found
081.             
082.                $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."'";
083.                $result_query=sqlsrv_query($con,$sql_update);
084.            }//end else num found
085.         }//end if entity
086.     $row++; 
087.      } //end foreach 
088.        
089.      $_SESSION["insert"]=$num_insert;
090.      move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES["file"]['name']);
091.      header('Location:http://uccinfo:85/rental/import.php');
092.     }//end if xml file
093.}//end if SubmitForm  
094.?>
095.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
097.<head>
098.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
099.<link type="text/css" href="css/default.css" rel="stylesheet"/>
100.<title>Import Excel File</title>
101.<script language="javascript" type="text/javascript">
102.function openDocDetail(url,width,height)
103.{
104.        var windowWidth=width;
105.        var windowHeight=height;
106.        var centerWidth = (window.screen.width - windowWidth) / 2;
107.        var centerHeight = (window.screen.height - windowHeight) / 2;
108.        OpenWindow=window.open(url, "","menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,resizable=no,width="+windowWidth+",height="+windowHeight+",top="+centerHeight+",left="+centerWidth);
109.}
110.</script>
111.</head>
112. 
113.<body>
114.<p><h2>Import ข้อมูลติดตั้งเครื่องเช่า</h2></p>
115.<form enctype="multipart/form-data" action="import_form.php" method="post">
116.<table width="95%" border="0" align="center" style="border-collapse:" >
117.  <tr>
118.    <td width="23%">เลือกไฟล์ (นามสกุล .xml) เท่านั้น</td>
119.    <td><input type="file" name="file" /></td>
120.  </tr>
121.  <tr>
122.    <td>&nbsp;</td>
123.    <td>&nbsp;</td>
124.  </tr>
125.  <tr>
126.    <td>&nbsp;</td>
127.    <td><label>
128.      <input type="submit" name="SubmitForm" value="Submit" />
129.      <input type="submit" name="Cancel" value="Cancel" />
130.    </label></td>
131.  </tr>
132.</table>
133.</form>
134.<ul id="menu">
135. <li><a href="#" onclick="javascript:openDocDetail('save_xml.php','1000','500');" class="txtlink">วิธี save file .xml</a></li>
136. <li><a href="upload_format.xls" class="txtlink">รูปแบบไฟล์สำหรับ import</a>
137. <li><a href="#" onclick="javascript:openDocDetail('all_upload.php','1100','500');" class="txtlink">ข้อมูลที่  import แล้ว</a></li>
138. <li><a href="manual/Manual_import.pdf" class="txtlink" target="_blank">คู่มือการ import</a></li>
139.<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>
140.</ul>
141.</body>
142.</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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





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