---
title: "nyheter+bild"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/132935-nyheter-bild"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "Krister"
published: "2005-08-18T09:14:18.000Z"
updated: "2005-08-18T09:14:18.000Z"
replies: 0
views: 272
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/132935-nyheter-bild"
---

# nyheter+bild

## #1 — Krister, 2005-08-18T09:14Z

Hej
Jag har ett scrip typ nyheter och skulle vilja att den som skriver in nyheterna även kan ladda upp en bild. 
Var lägger man in "uploadscripet utan komponent" då Scriptet ser ut så här

\<%  response.buffer = true  %\> 
\<html\>  

\<head\>  
\<title\>xx\</title\>  
\<style\>  
body, td { font-family: Verdana; color: black; font-size: 10px; }  
.table { padding-bottom: 9pt; padding-right: 9pt; padding-top: 10pt; }  
.div1 { padding-left: 9pt; padding-top: 9pt; }  
.nav1 { padding-left: 9pt; color: white; }  
.nav3 { padding-left: 9pt; color: black; font-size: 8pt; }  
.nav2 {padding-right: 9pt; color: white; }  
A { text-decoration: none; color: #113A67; }  
\</style\>
		\<meta name="site-config-URL" content="http://localhost/config/"\>
	\</head\>  

\<body bgcolor=white rightmargin=0 leftmargin=0 topmargin=0\>  

\<table border=0 width=100% cellspacing=0 cellpadding=0\>  
\<tr\>  	
\<td height=18 class=nav1 bgcolor="#2C5D92"\>Uppdatera din sida på ett lätt sätt\</td\>  	

\</table\>  

\<%  

if NOT (Session ("userAccess") = "granted") then  
	response.write ("\<form action=admin.asp method=post\>Användarnamn\<input type=hidden name=openMethod value=logIn\>  \<input type=text name=logIn size=10\> ID pass \<input type=password name=password size=10\>  \<input type=submit value='LoggIn'\>  \</form\> ")  

	openMethod = request.form ("openMethod")  
	login = request.form ("login")    
	password = request.form ("password")                       

	if openMethod = "logIn" and login = "XX" and password = "XX"  then                  
		Session ("userAccess") = "granted"  
		response.redirect ("admin.asp")
	End If
End If
%\>  
\<%  if Session("userAccess") = "granted" then  %\>  
\<%  page = request.queryString ("page")  %\>  
\<%  
'setting dsn connection
Set dc = Server.CreateObject("ADODB.Connection")  
Set rs = Server.CreateObject("ADODB.Recordset")  
dc.Open "DBQ=" & Server.Mappath("database.mdb") & ";Driver={Microsoft Access Driver (\*.mdb)};"  

'this function provides encoding, but since it's used in the guestbook script, \< and \> is no longer converted to HTML
Function EncodeData(source)  
	result1 = source
	result = ""
	for i = 1 to len(result1)
	resvalue=""
	if mid(result1,i,1)="'" then resvalue=resvalue+"''"
	if mid(result1,i,1)="\|" then resvalue=resvalue+"&brvbar;"
	if mid(result1,i,1)="&" then resvalue=resvalue+"&amp;"
	if mid(result1,i,1)="""" then resvalue=resvalue+"&quot;"
	if mid(result1,i,1)=chr(13) then resvalue=resvalue+"\<br\>"
	if resvalue\<\>"" then result = result + resvalue else result = result + Mid(result1, i, 1)
	next
	EncodeData = result
End Function
%\>

\<%  
'this code writes all the modifications to the database
action=request.queryString("action")
'we need to know what message should we deal with
msgId = request.queryString("msgId")
if action="submit" or action="delete" then  
'gets the data from the form

USER_MESSAGE = request.Form("USER_MESSAGE")  
USER_NAME = request.Form("USER_NAME") 
'converts the data to HTML format using the EncodeDara function
'since DB fields can't be zero-length, in case they're empty, we'll set them to " "

USER_MESSAGE = EncodeData(USER_MESSAGE)
USER_NAME = EncodeData(USER_NAME)   
'opens the database and writes data to it
select case action
case "delete"
	SQLCOMMAND = "DELETE GBOOK.\* FROM GBOOK WHERE (id = "& msgId &");" 
	DC.EXECUTE(SQLCOMMAND)  
case "submit"
	MYSQL = "SELECT GBOOK.\* FROM GBOOK WHERE (id = " & msgId & ")"
	rs.Open MYSQL, dc, 1, 3    
	rs.Fields("USER_NAME") = USER_NAME
	rs.Fields("USER_MAIL") = USER_MAIL
	rs.Fields("USER_CITY") = USER_CITY
	rs.Fields("USER_URL") = USER_URL
	rs.Fields("USER_MESSAGE") = USER_MESSAGE
	rs.Update
end select
response.redirect ("admin.asp") 
End If
%\>  

\<%  
action=request.queryString("action")
if action="modify" then  
msgId = request.queryString ("msgId")
MYSQL = "SELECT GBOOK.\* FROM GBOOK WHERE (id = "& msgId &")"  
rs.Open MySQL, dc, 3, 1 
%\>  

\<form action="/uppdatera/orum/admin.asp?action=submit&msgId=\<%=msgId%\>" method="post"\>  
\<table align=center border=0 cellspacing=0 cellpadding=0 width="317"\>  
	\</tr\> 
\<tr\>  \<td valign=top width="52"\>\<strong\>\<b\>Rubrik:\</b\>\</td\>\<td align=right width="265"\>\<textarea cols=30 rows=4 name=USER_NAME wrap=virtual\>\<%=rs("USER_NAME")%\>\</textarea\>\</td\>  \</tr\> 
  \</strong\>\<br\>
\<tr\>  \<td valign=top width="52"\>\<b\>Nuvarande text:\</b\>\</td\>\<td align=right width="265"\>\<textarea cols=30 rows=4 name=USER_MESSAGE wrap=virtual\>\<%=rs("USER_MESSAGE")%\>\</textarea\>\</td\>  \</tr\>  
\<tr\>  \<td width="52"\>&nbsp;\</td\>
  \<td height=50 valign=bottom align=right width="265"\>\<input type=submit value="ändra" onclick="return confirm('Nu är Ditt meddelande ändrat');"\>\</td\>  \</tr\>  
\</table\>  
\</form\> 
\</br\> 

\<% 
	rs.Close
	end if
%\>

\<table class=nav1 width=100% border=0 cellspacing=0 cellpading=0\>  \<tr\>  \<td colspan=6 height=18\>&nbsp;\</td\>  \</tr\>  \<tr bgcolor=#2C5D92\>  
  \<td height=18 class=nav1\>Nuvarande text\</td\>  
  \<td height=18 class=nav1 width=60 align=center\>välj\</td\>  \</tr\>  \</table\>   
\<table class=nav3 width=100% border=0 cellspacing=0 cellpading=0\>  
\<%  
	MYSQL = "SELECT ID, USER_MAIL, USER_NAME, USER_DATE, USER_CITY, USER_MESSAGE FROM GBOOK ORDER by ID DESC"  
	rs.Open MySQL, dc, 3, 1  
%\>  
\<% Do While (Not rs.EOF) %\>  
	\<tr\>\<td colspan=6 height=18\>&nbsp;\</td\>\</tr\>  
	\<tr\>\<td height=18 class=nav3 width=122\>\<% if len(rs("USER_DATE")) \> 10 then %\> \<% = (left(rs("USER_DATE"),10) & "") %\> \<% else %\> \<% = (rs("USER_DATE")) %\> \<% End If %\>\</td\>  \<td height=18 class=nav3\>\<% if len(rs("USER_NAME")) \> 12 then %\> \<% = (left(rs("USER_NAME"), 30) & "...") %\> \<% else %\> \<% = (rs("USER_NAME")) %\> \<% End If %\>\</td\>  \<td height=18 class=nav3 width=100\>\<a href='mailto: \<%=rs("USER_MAIL")%\>'\>\<% if len(rs("USER_MAIL")) \> 15 then %\> \<% = (left(rs("USER_MAIL"), 15) & "...") %\> \<% else %\> \<% = (rs("USER_MAIL")) %\>\</a\> \<% End If %\>\</td\>  \<td height=18 class=nav3\>\<% if len(rs("USER_MESSAGE")) \> 40 then %\> \<% = (left(rs("USER_MESSAGE"), 40) & "...") %\> \<% else %\> \<% = (rs("USER_MESSAGE")) %\> \<% End If %\>\</td\>
				\<td height=18 class=nav3 width=60 align=center\>T\<a href='/././admin.asp?action=delete&msgId=\<%=rs("ID")%\>' name=msg\<%=rs("ID")%\> onclick="return confirm('Är du säker på att du ska ta borta detta?');"\>a bort \</a\>\<br\>\<a href='/uppdatera/orum/admin.asp?action=modify&msgId=\<%=rs("ID")%\>'\>Redigera\</a\>\<br\>
					\<a href="/././gbook1.asp"\>L&auml;gg till\</a\>\</td\>
			\</tr\>  
\<% 
	rs.MoveNext 
	Loop 
%\>  
	\<tr\>\<td colspan=6 height=18\>&nbsp;\</td\>\</tr\>  
\</table\>  

\<% 
rs.Close
Set rs = Nothing
dc.Close
Set dc = Nothing 
%\> 
\<% End If %\>  

\<table border=0 width=100% cellspacing=0 cellpadding=0\>  
\<tr\>  	
\<td height=18 class=nav1 bgcolor="#2C5D92" \>\</td\>  	
\<td align=right height=18 class=nav2 bgcolor="#2C5D92"\>\<% = formatDateTime(now, 1) %\>\</td\>  
\</tr\>  
\</table\>  

\</body\>
\</html\>

Permalänk: https://www.webforum.nu/p/132935

---

Tråden på webben: https://www.webforum.nu/amne/asp/132935-nyheter-bild
