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 > ASP > ASP Forum > โค้ด ASP ทำ Webboard ติดปัญหาตรงที่ไม่ยอมเขียนลงในไฟล์ txt



 

โค้ด ASP ทำ Webboard ติดปัญหาตรงที่ไม่ยอมเขียนลงในไฟล์ txt

 



Topic : 049314

Guest




พอดีผมได้โค้ด ASP เกี่ยวกับบอร์ดทางเน็ตมาแล้วประยุกต์ใช้กับงานครับ ตอนแรกก็สามารถรันดูข้อความในบอร์ดที่เราเขียนได้ โดยข้อความที่เขียนจะถูกเก็บในไฟล์ .txt และอยู่ดีๆ(หลังจากรีสตาร์คอมพิวเตอร์)ก็ไม่สามารถแสดงข้อความในบอร์ดที่เขียน ดูแล้วในไฟล์ .txt ไม่มีการเขียนข้อมูลลงไป หน้าบอร์ดเลยไม่แสดงข้อมูลที่เขียนไว้ (ขึ้นหน้าจอว่าง)
โค้ดมี 3 ไฟล์ครับ

1.ไฟล์หน้าหลักสำหรับเขียนข้อความ

<html>
<head>
<title>Message board</title>

</head>
<body bgcolor=black text=white link=yellow vlink=lightgrey>


<center><br>
<font face="System, Ms Sans Serif, Angsana UPC, Thonburi, Krungthep" size="1">
Hi, you can type your message here Yes... any you like . .</font>

<form method="post" action="add.asp">
<table border="0" width="64%" cellpadding="3">
<tr bgcolor="#C0C0C0">
<td width="13%" bgcolor="#D1D1D1"><font face="MS Sans Serif" size="2" color="#000000">Name:</font></td>
<td width="87%" bgcolor="#E5E5E5"><font face="MS Sans Serif" size="2" color="#000000"><input
type="text" size="25" maxlength="256" name="fname"> </font></td>
</tr>
<tr>
<td width="13%" bgcolor="#D1D1D1"><font face="MS Sans Serif" size="2" color="#000000">Email:</font></td>
<td width="87%" bgcolor="#E5E5E5"><font face="MS Sans Serif" size="2" color="#000000"><input
type="text" size="25" maxlength="256" name="info"> </font></td>
</tr>
<tr>
<td width="13%" bgcolor="#D1D1D1" valign="top" align="left"><font face="MS Sans Serif"
size="2" color="#000000">Message:</font></td>
<td width="87%" bgcolor="#E5E5E5"><font face="MS Sans Serif" size="2" color="#000000"><b><textarea
name="memo" rows="4" cols="38">

</textarea> </b></font></td>
</tr>
<tr>
<td width="13%" bgcolor="#D1D1D1">&nbsp;</td>
<td width="87%" bgcolor="#D1D1D1"><br>
<b><font face="MS Sans Serif" size="2" color="#000000">
<input type="hidden" name="mode" value="1"><input type="submit" name="Submit"
value="Submit"> &nbsp;&nbsp; <input type="reset" name="_reset" value="Reset"> </font></b></td>
</tr>
</table>
<br>


</FORM>
<img src="/images/direction_right.gif" border="0" WIDTH="20" HEIGHT="16">
<font face="Ms Sans Serif, System, Angsana UPC, Thonburi, Krungthep" size="1"><b><a href="display.asp">อ่านข้อความ</a></b></font>
</center>
<br>
<hr noshade size="-1">

</body>
</html>



2.ไฟล์เขียนข้อมูลลง .txt ไฟล์
<%
' ถ้าป้องกันการ post ซ้ำ
' if session("sendtonight") = "sended" then
' response.redirect("display.asp")
' end if

thisfile = "add.asp"
msgfile = ".txt"
mode = Request.Form("mode")
if (mode="") then
Response.Redirect("main.asp")
else

'ถ้าตรวจสอบคำหยาบใส่ตรงนี้ได้เลย

savemode = "passbad"
polite = "yes"
end if

if (polite="yes") then
accmemo = ""

'จำกัดความยาว
msg1=Request.Form("memo")
n = len(msg1)
if n > 2400 then
adot="..."
memo2 = Left(msg1,2390) + adot
else
memo2 =msg1
end if

'ใส่ code ขึ้นบันทัดใหม่ และเว้นช่องว่าง
smemo = memo2
if (len(smemo)<1000) then
n = len(smemo)
else
n = 1000
end if
for i = 1 to n
char = mid(smemo,i,1)
ascii = asc(char)
if (ascii=13) then
char = "<br>"
elseif (ascii=32) then
char = "&nbsp;"
end if
accmemo = accmemo+char
next

'ไม่ให้ใช้ html
accinfo = ""
sinfo = trim(Request.Form("info"))
n = len(sinfo)
for i = 1 to n
char = mid(sinfo,i,1)
ascii = asc(char)
if (ascii=13) then
char = "<br>"
elseif (ascii=32) then
char = "&nbsp;"
elseif (ascii=60) then
char = "&lt;"
elseif (ascii=62) then
char = "&gt;"
end if
accinfo = accinfo+char
next

accfname = ""
sname = trim(Request.Form("fname"))
n = len(sname)
for i = 1 to n
char = mid(sname,i,1)
ascii = asc(char)
if (ascii=13) then
char = "<br>"
elseif (ascii=32) then
char = "&nbsp;"
elseif (ascii=60) then
char = "&lt;"
elseif (ascii=62) then
char = "&gt;"
end if
accfname = accfname+char
next

%>





<%
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
TestFile = Server.MapPath ("text.txt")
On Error Resume Next
Set InStream= FileObject.OpenTextFile (TestFile, 1, false )

'จำกัดการ post ไว้
Dim lines(40)
LnCnt = 0
While not InStream.AtEndOfStream
InLine=Instream.ReadLine()
If Len(InLine) > 3 Then
LnCnt=LnCnt+1
lines(LnCnt) = InLine
End If
Wend

On Error Resume Next
d2=FormatDateTime(date,vbLongDate)
filecontents=Trim(InStream.ReadALL)
'ปรับแต่งหน้าตาตัวอักษรตรงนี้
textstr="&nbsp;&nbsp;&nbsp;<font size=1 face=system>" & accmemo & "<br>โดย:</font> <a href=mailto:" &accinfo&"><font color=ff00ff size=1 face=system>" & accfname & "</a></font> - <font face=system size=1>" &d2& "</font><HR noshade size=-1>"
Set OutStream= FileObject.CreateTextFile (TestFile, True)
OutStream.WriteLine(textstr)
OutStream.WriteLine(filecontents)

For i = 1 to 40
Outstream.WriteLine lines(i)
Next

Set OutStream = Nothing
Set textstr =Nothing
Set Instream = Nothing
Set filecontents =Nothing
session("sendtonight") = "sended"
%>

<html>
<head>
<title>Message board</title>

</head>
<body bgcolor=black text=white link=yellow vlink=lightgrey>
<pre>

</pre>
<center>
<font face="Ms Sans Serif, System, Angsana UPC, Thonburi, Krungthep" size="1">
<b> เราได้รับข้อความของคุณ<%=Request.form("fName") %>แล้ว <br>Thanks you</b></font><br>
<br>
<img src="/images/direction_right.gif" border="0" WIDTH="20" HEIGHT="16"> <font face="Ms Sans Serif, System, Angsana UPC, Thonburi, Krungthep" size="1"><b><a href="display.asp">อ่านข้อความ</a></b></font>
</center>
</body>
</html>

<%End if%>

3.ไฟล์โชว์ข้อความที่เขียน
<html>
<head>
<title>Message board</title>

</head>
<body bgcolor=black text=white link=yellow vlink=lightgrey>

<center>

<br><br>
<font face="Ms Sans Serif, System, Angsana UPC, Thonburi, Krungthep" size="3"><b>
Your page title go here</b></font><br>
<font SIZE="3">say something right here... say something right here... say something right here...<br>
<font size=2><a href=mailto:[email protected]>[email protected]</a> </font>
<br></center>
<img src="/images/direction_right.gif" border="0" WIDTH="20" HEIGHT="16"> <a href="main.asp"><font size="1" face=system><b>เขียนข้อความ</b></font></a><br><br>
<br>


<%
'เปิดไฟล์ แล้วนำข้อมูลที่อ่านได้มาเขียนลงไป
Set FileObject = Server.CreateObject("Scripting.FileSystemObject")
ChatFile = Server.MapPath ("text.txt")
On Error Resume Next
Set InStream= FileObject.OpenTextFile (ChatFile, 1, False, False)
Response.Write Instream.ReadALL & "<BR>"
Set Instream=Nothing
%>

<img src="/images/direction_right.gif" border="0" WIDTH="20" HEIGHT="16"> <a href="main.asp"><font size="1" face=system><b>เขียนข้อความ</b></font></a><br><br>
<br>
<hr noshade size="-1">

</body>
</html>
ขอความช่วยเหลือด้วยค๊าฟ



Tag : ASP, HTML/CSS







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-09-25 10:47:22 By : ต้อง View : 1585 Reply : 3
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

ติด Permission หรือเปล่าครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 11:22:29 By : webmaster
 


 

No. 2



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



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


แต่ตอนแรกที่เขียนเสร็จแล้วอะคับ มันสามารถโพสต์ข้อความได้ แสดงโชว์ได้น๊ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 11:46:11 By : tong09
 

 

No. 3



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



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


ทำได้แล้วครับ จิงๆด้วยสงสัยลบไฟล์ text.txt อันเก่าทิ้ง ที่เซ็ต Premission ไว้แล้ว
ขอบคุณครับที่ให้คำแนะนำ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-25 11:50:18 By : tong09
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : โค้ด ASP ทำ Webboard ติดปัญหาตรงที่ไม่ยอมเขียนลงในไฟล์ txt
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 02
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 อัตราราคา คลิกที่นี่