  | 
		 		   | 
	  	    
          
            
			
	
			
			 
               ผมเขียนโค้ดให้ insert ข้อมูลลง ตารางครับ แล้วก็จะมี upload ภาพลงfolder แล้วเก็บพาธเอาไว้ในฐานข้อมูลครับ 
 
ผมเขียนโค้ดแบบนี้เอาไว้สองสามครั้งแล้ว แล้วก็มีของเพื่อนอีก มันคล้ายๆกันครับ 
อันอื่นไม่มีปัญหา แต่อันนี้ โค้ดเหมือนๆกัน แค่ตัวแปร กับจำนวนฟิลล์ที่ลงตารางไม่เหมือนกันเท่านั้น แต่กลับ error ครับ 
มันเป็นแบบนี้ครับ 
 
Error Type: 
Microsoft VBScript runtime (0x800A0005) 
Invalid procedure call or argument 
/alumnus/act_member.asp, line 23 
 
แล้วก็ในโฟลเดอร์ที่ใช้เก็บรูปภาพ มันมีไฟล์รูปภาพนั้นอยู่ครับแต่เป็น o bytes 
 
ผมลองให้อาจารย์ช่วยดู อาจารย์เองท่านก็งงเหมือนกันครับไม่ทราบเป็นอะไร 
ผมจะเอาโค้ดมาให้ดูนะครับ 
แต่มีอยู่ครั้งนึง ผมเพิ่ง format เครื่องใหม่ แล้วลอง run ดู มันทำได้ครั้งนึงครับ insert ข้อมูลลงแฟ้มข้อมูลทุกอย่าง 
แต่พอลองอีกที ก็ไม่ได้แล้วอ่ะครับ 
ผมคิดเอาเองนะครับว่าน่าจะเป็นที่โปรแกรมอะไรสักอย่างในเครื่อง แต่ script blocking ของ norton ผมเอาออกแล้วนะครับ 
ขอความกรุณาผู้ทราบช่วยแนะนำด้วยครับ 
 
 
'member.asp 
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
<!--#include file="connect.asp" --> 
<html> 
<head> 
<title>Untitled Document</title> 
<meta http-equiv="Content-Type" content="text/html; charset=windows-874"> 
</head> 
 
<body> 
<form action="act_member.asp" method="post" enctype="multipart/form-data" name="form1"> 
  <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0"> 
    <tr bordercolor="#FFFFFF" bgcolor="#33CCFF">  
      <td colspan="4"><font color="#666666">กรุณากรอกข้อมูลเพื่อตรวจสอบ</font></td> 
    </tr> 
    <tr>  
      <td width="16%"> </td> 
      <td width="27%">รหัสนักศึกษา</td> 
      <td width="31%"> </td> 
      <td width="26%"> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>วัน/เดือน/ปีเกิด</td> 
      <td> </td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td> </td> 
      <td> </td> 
      <td> </td> 
    </tr> 
    <tr bgcolor="#33CCFF">  
      <td height="20" colspan="4"><font color="#666666">กรุณากรอกข้อมูลเพื่อสมัครสมาชิก</font></td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>ชื่อ</td> 
      <td><font size="2">  
        <input name = name type = text id="name" onKeyPress="return keyCheck(event, this)" size="30" maxlength="10"> 
        </font><font color="#FF0000">*</font><font size="2"><br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>นามสกุล</td> 
      <td><font size="2">  
        <input name = surname type = text id="surname" onKeyPress="return keyCheck(event, this)" size="30" maxlength="10"> 
        </font><font color="#FF0000">*</font><font size="2"><br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>ที่อยู่</td> 
      <td><font size="2">  
        <textarea name = address cols = 35 rows = 5 id="address"></textarea> 
        </font><font color="#FF0000">*</font><font size="2"> <br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td height="26"> </td> 
      <td>จังหวัด</td> 
      <td><font size="2">  
        <% 
Sql="Select * From province"  
Set Rs1=conn.execute(sql) 
%> 
        <select name="province" id="province" > 
          <option>เลือกจังหวัด</option> 
          <%while Not Rs1.EOF%> 
          <option value=<% =Rs1("province_id")%>>  
          <% =Rs1("province_name")%> 
          </option> 
          <% 
						  Rs1.MoveNext 
						  wend 
						rs1.close 
					%> 
        </select> 
        </font><font color="#FF0000">*</font><font size="2"><br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>เบอร์โทรศัพท์</td> 
      <td><font size="2">  
        <input name = phone type = text id="phone" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30"> 
        </font><font color="#FF0000">*</font><font size="2"><br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>เบอร์โทรศัพท์มือถือ</td> 
      <td><font size="2">  
        <input name = mobile type = text id="mobile" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30"> 
        </font><font size="2"><br> 
        <br> 
        </font></td> 
      <td><font color="#FF0000"> </font></td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>e-mail</td> 
      <td><font size="2">  
        <input name = email type = text id="email" onKeyPress="return keyCheck(event, this)" size="30" maxlength="50"> 
        </font><font color="#FF0000">*</font><font size="2"><br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>รูปภาพ</td> 
      <td><font size="2">  
        <input  name="pics" type="file"  class="input_button3" id="pics" size="30"> 
        <br> 
        </font></td> 
      <td><font color="#FF0000"> </font></td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>username</td> 
      <td><font size="2">  
        <input name = username type = text id="username" onKeyPress="return keyCheck(event, this)" size="30" maxlength="10"> 
        </font><font color="#FF0000">*</font><font size="2"> <br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>password</td> 
      <td><font size="2">  
        <input name = password type = text id="password" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30"> 
        </font><font color="#FF0000">*</font><font size="2"><br> 
        <br> 
        </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>กรุณาเลือกคำถาม</td> 
      <td><select name="question" text="กรุณาเลือกคำถาม"> 
          <option selected>กรุณาเลือกคำถาม</option> 
          <option value="ชื่อสัตว์เลี้ยง">ชื่อสัตว์เลี้ยง</option> 
          <option value="สีที่ชอบ">สีที่ชอบ</option> 
          <option value="ชื่อคนรัก">ชื่อคนรัก</option> 
          <option value="ดารานักร้องที่ชื่นชอบ">ดารานักร้องที่ชื่นชอบ</option> 
        </select> 
        <font color="#FF0000">*</font><br> 
        <br> 
      </td> 
      <td><font color="#FF0000">*</font><font color="#FF0000">*</font>ในกรณีที่ลืมรหัสผ่าน</td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td>คำตอบ</td> 
      <td><font size="2">  
        <input name = answer type = text id="answer" onKeyPress="return keyCheck(event, this)" size="30" maxlength="30"> 
        </font><font color="#FF0000">*</font><font size="2">  </font></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td> </td> 
      <td> </td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td> </td> 
      <td><input name="submit" type = submit value = "บันทึกข้อมูล"  class="input_button3" >  
           <input name="reset" type = reset value = "ลบข้อมูล" class="input_button3"></td> 
      <td> </td> 
    </tr> 
    <tr>  
      <td> </td> 
      <td> </td> 
      <td> </td> 
      <td> </td> 
    </tr> 
  </table>  <p>หมายเหตุ กรุณากรอกข้อมูลในช่องที่มี * ให้ครบถ้วน</p> 
</form> 
<p> </p> 
</body> 
</html> 
'================================================================= 
 
 
'act_member.asp 
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
<!--#include file="getuploaddata.asp"--> 
<!--#include file="connect.asp"--> 
<% 
if uploaddata.Item("name").Item("value")="" or _ 
uploaddata.Item("surname").Item("value")="" or _ 
uploaddata.Item("address").Item("value")="" or _ 
uploaddata.Item("province").Item("value")="" or _ 
uploaddata.Item("phone").Item("value")="" or _ 
uploaddata.Item("email").Item("value")="" or _ 
uploaddata.Item("username").Item("value")="" or _ 
uploaddata.Item("password").Item("value")="" or _ 
uploaddata.Item("question").Item("value")="" or _ 
uploaddata.Item("answer").Item("value")=""  then 
response.write"<center><input type=button class=input_button3 value='กรอกข้อมูลไม่ครบ กลับไปกรอกข้อมูลใหม่ !!' onClick='history.go(-1)' ></center>"  
else 
 
filename = uploaddata.Item("pics").Item("filename") 
pos_filebegin = InStrRev(filename,"\") 
pos_fileend = Len(filename) 
filename_new = Mid(filename,pos_filebegin+1,pos_fileend - pos_filebegin) 
set fs = Server.CreateObject("Scripting.FileSystemObject") 
set uploadfile = fs.CreateTextFile(Server.MapPath("file/"&filename_new)) 
uploadfile.write uploaddata.Item("pics").Item("value") 
uploadfile.close  
 
filename_new="file\"&filename_new 
userid = session("username") 
sql2 = "Select * from member where username='"&uploaddata.Item("username").Item("value")&"'" 
Set rs1 = Server.CreateObject("ADODB.Recordset") 
 
rs1.Open sql2, conn, 1,3,512 
response.write(sql2) 
if (Rs1.EOF) Then	 
sql="select * from member" 
Set rs = Server.CreateObject("ADODB.Recordset") 
rs.Open sql, conn, 1,3 
if rs.recordcount <> 0 then 
rs.addnew 
rs("name")=uploaddata.Item("name").Item("value") 
rs("surname")=uploaddata.Item("surname").Item("value") 
rs("address")=uploaddata.Item("address").Item("value") 
rs("province_id")=uploaddata.Item("province").Item("value") 
rs("phone")=uploaddata.Item("phone").Item("value") 
rs("mobile")=uploaddata.Item("mobile").Item("value") 
rs("e_mail")=uploaddata.Item("email").Item("value") 
rs("picture")=filename_new 
rs("username")=uploaddata.Item("username").Item("value") 
rs("password")=uploaddata.Item("password").Item("value") 
rs("question")=uploaddata.Item("question").Item("value") 
rs("answer")=uploaddata.Item("answer").Item("value") 
rs.Update 
 With Response 
      .Write "<br><br><table align=center width=400 cellspacing=0 cellpadding=0 bgcolor=#ff6600><tr><td>" 
      .Write "<table align=center border=0 width='100%' cellpadding=1 cellspacing=1>" 
      .Write "<tr><td bgcolor=#ffffcc align=center>" 
	  .Write "<b>Status : </b>  <IMG SRC=picturs/icon_mini_register.gif >บันทึกข้อมูลเข้าสู่ระบบเรียบร้อยแล้ว " 
	  .Write "</td></tr></table>" 
      .Write "</td></tr></table>" 
   End With 
rs.close 
else 
end if   
else 
With Response 
      .Write "<br><br><table align=center width=400 cellspacing=0 cellpadding=0 bgcolor=#ff6600><tr><td>" 
      .Write "<table align=center border=0 width='100%' cellpadding=1 cellspacing=1>" 
      .Write "<tr><td bgcolor=#ffffcc align=center>" 
	  .Write "<b>Status : </b>  มีผู้ใช้ชื่อ user name นี้แล้ว" 
	  .Write "</td></tr></table>" 
      .Write "</td></tr></table>" 
   End With 
   rs1.close 
   end if 
end if 
%> 
<table width="200" border="0" cellspacing="0" cellpadding="0" align="center"> 
  <tr> 
    <td align="right" bgcolor="#66CCFF"> </td> 
  </tr> 
  <tr> 
    <td align="right" bgcolor="#66CCFF"><font size="2"> <font color="#FF0000"><a href="javascript:self.close();" ><font size="3">close  
      windows </font></a></font></font></td> 
  </tr> 
 
</table> 
'========================================================= 
 
 
'connect.asp 
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
	<% 
Set Conn=Server.CreateObject("ADODB.Connection") 
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE="&Server.MapPath("data.mdb") 
	%> 
'========================================================= 
 
'getuploaddata.asp 
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
<% 
'-- ฟังค์ชั่นเปลี่ยน ข้อความ เป็น ข้อมูลไบนารี --  
Function TextToBinary(text) 
	for i = 1 to Len(text)  
		character = mid(text,i,1) 
		TextToBinary = TextToBinary & ChrB(Asc(character)) 
	next 
End Function 
 
'-- ฟังค์ชั่นเปลี่ยน ข้อมูลไบนารี กลับเป็น ข้อความ --  
Function BinaryToText(Binary) 
	BinaryToText="" 
	for i =1 to LenB(Binary) 
		character = MidB(Binary,i,1) 
		BinaryToText = BinaryToText & Chr(AscB(character)) 
	next 
End Function 
 
'-- กำหนดการใช้ Dictionary ทำให้เก็บข้อมูลได้มากคล้ายกับ Array  --  
set uploaddata = CreateObject("Scripting.Dictionary") 
 
data = request.BinaryRead(request.TotalBytes) 
posend = InstrB(1,data,TextToBinary(chr(13))) 
header = MidB(data,1,posend-1) 
 
endheader = header & TextToBinary("---") 
pos_header = 1 
pos_endheader = InstrB(1,data,endheader) 
 
'-- การวนลูปเพื่อตัดข้อมูลที่ถูกส่งมาให้ครบทั้งหมด --  
Do While pos_header <> pos_endheader 
	 
	set sub_uploaddata = CreateObject("Scripting.Dictionary") 
 
	'--ตัดชื่อ (ชื่อตัวแปรของช่อง) ช่องกรอกข้อมูลงทุกรูปแบบ เช่น textbox radio combobox เป็นต้น -- 
	pos_name = InstrB(pos_header,data,TextToBinary("name=")) 
	pos_namebegin = pos_name + 6 
	pos_nameend = InstrB(pos_namebegin,data,TextToBinary(chr(34))) 
	name = BinaryToText(MidB(data,pos_namebegin,pos_nameend - pos_namebegin)) 
 
	'-- ตรวจสอบว่าข้อมูลเป็นแบบปกติ หรือ เป็นช่องอัพโหลดไฟล์(ช่องอัพโหลดจะมีลักษณะขอ้มูลแตกต่างจากทั่ว ๆ ไป) 
	pos_file = InstrB(pos_nameend,data,TextToBinary("filename")) 
	enddata  = InstrB(pos_nameend,data,header) 
	if (pos_file <> 0) and (pos_file < enddata) then 
		 
		'---ข้อมูลเป็นชนิดไฟล์อัพโหลด ให้ทำการตัดชื่อไฟล์ออกมา (ชื่อไฟล์เป็น Value ของตัวอัพโหลดไฟล์)-- 
		pos_filebegin = pos_file + 10 
		pos_fileend = InstrB(pos_filebegin,data,TextToBinary(chr(34))) 
		filename = BinaryToText(MidB(data,pos_filebegin,pos_fileend - pos_filebegin)) 
		 
		'--เก็บข้อมูลชื่อไฟลไว้ในออบเจ็ค Dictionary-- 
		sub_uploaddata.add "filename", filename 
 
		pos_content = InstrB(pos_fileend,data,TextToBinary("Content-Type:")) 
		pos_contentbegin = pos_content + 14 
		pos_contentend = InstrB(pos_contentbegin,data,TextToBinary(chr(13))) 
		contenttype = BinaryToText(MidB(data,pos_contentbegin,pos_contentend - pos_contentbegin)) 
 
		'--เก็บข้อมูล ชนิดของไฟล์ที่อัพโหลด (Content - Type) ในออบเจ็ค Dictionary-- 
		sub_uploaddata.add "contenttype", contenttype 
 
		'--ตัดข้อมูลภายในไฟล์รูปภาพ-- 
		pos_valuebegin = pos_contentend + 4 
		pos_valueend = InstrB(pos_valuebegin,data,header) - 2 
		value = BinaryToText(MidB(data,pos_valuebegin,pos_valueend - pos_valuebegin)) 
 
		'--เก็บข้อมูลภายในไฟล์รูปภาพ ลงในออบเจ็ค Dictionary-- 
		sub_uploaddata.add "value",value 
	 
	 
	else 
 
		'--ตัดข้อมูลภายในไฟล์ทั่วไป(ไม่ใช่รูปภาพ)-- 
		pos_valuebegin = pos_nameend + 5 
		pos_valueend = InstrB(pos_valuebegin,data,header) - 2 
		value = BinaryToText(MidB(data,pos_valuebegin,pos_valueend - pos_valuebegin)) 
		 
		'--เก็บข้อมูลภายในไฟล์ทั่วไป ลงในออบเจ็ค Dictionary-- 
		sub_uploaddata.add "value",value 
	 
	end if 
	 
 
	'-- เก็บข้อมูลทั้งหมดลงใน Dictionary ชื่อ uploaddata-- 
	uploaddata.add name,sub_uploaddata 
 
	'--เปลี่ยนตำแหน่ง Header ไปยังข้อมูลถัดไป(ถ้าหากมี) โดยทำการวนลูปเช็คเงื่อนไข-- 
	pos_header = InstrB(pos_header+LenB(header),data,header) 
loop 
%> 
'================================================================    
 
  Tag : - - - -              
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          6 ธ.ค. 2547  23:48:31 | 
                      By :
                          gototon | 
                      View :
                          3206 | 
                      Reply :
                          3 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |