Foros del Web » Programando para Internet » ASP Clásico »

Problemas con un código

Estas en el tema de Problemas con un código en el foro de ASP Clásico en Foros del Web. Hola amigos agradeceria su ayuda para encontrar el problema en este código.. Show.asp Código: <% dim conn dim rs set conn = Server.CreateObject("ADODB.Connection") set rs ...
  #1 (permalink)  
Antiguo 24/07/2004, 23:13
Avatar de El_Metallick  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 6 meses
Puntos: 16
Problemas con un código

Hola amigos agradeceria su ayuda para encontrar el problema en este código..
Show.asp
Código:
<%
dim conn 
dim rs 

set conn = Server.CreateObject("ADODB.Connection") 
set rs = Server.CreateObject("ADODB.Recordset") 
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("cds.mdb")

conn.Open strCon

rs.ActiveConnection = conn
rs.Open "SELECT * FROM cds ORDER BY title ASC" 
while not rs.EOF 
%> 
<font face="Verdana" size="2" color="black"> 
<h2><%=rs.Fields(1).Value%></h2> 
<b>Author:</b> <%=rs.Fields(2).Value%><br> 
<b>Summary:</b> <%=rs.Fields(3).Value%><br> 
<b>Price:</b> <%=FormatCurrency(rs.Fields(4).Value, 2)%><br> 
</font> 
<br> 
<form name="frmRate<%=rs.Fields(0).value%>" action="rate.asp"> 
<input type="hidden" name="cdId" value="<%=rs.Fields(0).value%>"> 
<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td bgcolor="black"> 
<font face="Verdana" size="1" color="white"> 
<% 
for i = 1 to 10 
Response.Write "&nbsp;" & i & " <input name=""rating"" type=""radio"" value=""" & i & """> " 
next 
%> 
</font> 
<input type="submit" value="Rate It!"> 
</td> 
</tr> 
</table> 
</form> 
<hr size="1" color="#08496B" NOSHADE> 
<% 
rs.MoveNext 
wend 
%>
Rate.asp
Código:
<% 

dim conn 
dim rs 
dim cdId 
dim visitorIP 
dim rating 
dim cookie 
dim cookieRated 

cdId = Request.Form("cdId") 
rating = Request.Form("rating") 
visitorIP = Request.ServerVariables("REMOTE_ADDR") 
cookie = Request.Cookies("rate_" & cdId) 
set conn = Server.CreateObject("ADODB.Connection") 
set rs = Server.CreateObject("ADODB.Recordset") 
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("cds.mdb")

conn.Open strCon
rs.ActiveConnection = conn 
if cookie = "" then 
cookieRated = false 
else 
cookieRated = true 
end if 
if rating = "" then 

'Invalid rating 
%> 

<font face="Verdana" size="2" color="black"> 
<h2>Invalid Rating</h2> 
You must select a rating first!<br><br> 
<a href="javascript:history.go(-1)">Go Back</a> 
</font> 

<% 

else 

'Valid rating, make sure visitor hasn't already voted 
'by checking the ratings table 
rs.Open "SELECT COUNT(*) FROM ratings WHERE ip='" & visitorIP & "' AND cdId=" & cdId 
if rs.Fields(0).Value = 0 then 
if cookieRated = false then 
'Visitor hasn't rated yet, let's add it 
conn.Execute "INSERT INTO ratings(rating, ip, cdId) VALUES(" & rating & ", '" & visitorIP & "', " & cdId & ")" 

Response.Cookies("rate_" & cdId) = true 
Response.Cookies("rate_" & cdId).expires = Date() + 30 
%> 
<font face="Verdana" size="2" color="black"> 
<h2>Thank You For Rating!</h2> 
Your CD rating has been added to our database.<br><br> 
<a href="showcds.asp">Continue</a> 
</font> 
<% 
else
'Visitor has already rated this article 
%> 
<font face="Verdana" size="2" color="black"> 
<h2>Already Rated</h2> 
You have already rated this article!<br><br> 
<a href="javascript:history.go(-1)">Go Back</a> 
</font> 
<% 
end if
%>
<%
else 
'Visitor has already rated this article 
%> 
<font face="Verdana" size="2" color="black"> 
<h2>Already Rated</h2> 
You have already rated this article!<br><br> 
<a href="javascript:history.go(-1)">Go Back</a> 
</font> 
<% 
end  if
%>
<% 
end  if
%>
Showrating.asp
Código:
<%
function ShowRating(cdId) 

const MIN_RATINGS_BEFORE_SHOW = 3 

dim rs1 
dim avgRating 
dim avgWhole 
dim decPart 
dim decCalc 
dim finalRating 
dim altText 
set rs1 = Server.CreateObject("ADODB.Recordset") 

rs1.ActiveConnection = conn 
rs1.Open "SELECT SUM(rating), COUNT(*) FROM ratings WHERE cdId = " & cdId 

if rs1.Fields(1) < MIN_RATINGS_BEFORE_SHOW then 
'No ratings for this CD just yet 
Response.Write "[CD not rated yet]" 
else 

'This CD has ratings, let's display the average 
avgRating = rs1.Fields(0).Value / rs1.Fields(1).Value 
if Instr(1, CStr(avgRating), ".") > 0 then 

'The average rating is a decimal, we need to either 
'round the value up/down 

avgWhole = Left(CStr(avgRating), Instr(1, CStr(avgRating), ".")-1) 
decPart = Mid(CStr(avgRating), Instr(1, CStr(avgRating), ".")+1, 2) 

if decPart <> "" then 
'Work out whether or not we have to round this 
'rating up or down 

if CInt(decPart) >= 5 then 
decCalc = .5 
else 
decCalc = 0 
end if 

finalRating = CInt(avgWhole) + CCur(decCalc) 

else 
finalRating = avgRating 
end if 
else 
finalRating = avgRating 
end if 
'Setup the alt text for the images 
altText = "Average visitor rating of " & finalRating & " out of 10" 

for i = 1 to CInt(finalRating) 
Response.Write "<img alt='" & altText & "' src='rating_on.gif'>" 
next 

if CInt(finalRating) <> finalRating then 
'This article has a .5 rating, such as 5.5 
Response.Write "<img alt='" & altText & "' src='rating_half.gif'>" 

for i = CInt(finalRating)+2 to 10 
Response.Write "<img alt='" & altText & "' src='rating_off.gif'>" 
next 
else 
for i = CInt(finalRating)+1 to 10 
Response.Write "<img alt='" & altText & "' src='rating_off.gif'>" 
next 
end if 
%>
En el navegador me tira errores de tipo de sintaxis como se esperaba End y cosas asi no se que puede ser en todo caso si quieren probar el script entero la base de datos contiene los siguientes campos:
Tabla cds:
cdId--------Autonumérico
title---------texto
artist--------texto
summary---texto
price--------numérico

Tablaratings:
ratingId-------autonumérico
rating---------numérico
ip--------------numérico
cdId-----------numérico

Bueno de antemano muchas gracias y adios
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!
  #2 (permalink)  
Antiguo 25/07/2004, 02:29
 
Fecha de Ingreso: julio-2004
Mensajes: 11
Antigüedad: 20 años, 9 meses
Puntos: 0
Exclamación Falta cerrer un if

Pues mira "El_Metallick", asi a simple vista, y por el error que dices que te marca, creo que ese error te lo debe de dar en la pagina "Showrating.asp" ya que te falta cerrar la primera sentencia de control "if" que vendria siendo hasta el final del código de esa página, o en su defecto, debes checar cual es el que se te olvido cerrar.

Espero que con eso te funcione.
  #3 (permalink)  
Antiguo 25/07/2004, 09:04
Avatar de El_Metallick  
Fecha de Ingreso: noviembre-2002
Ubicación: Santiago, Chile
Mensajes: 1.718
Antigüedad: 22 años, 6 meses
Puntos: 16
En efecto amigo el código tira errores en esra página pero tb tira errores en la página rate.asp... no se que puede ser... gracias por tu ayuda.
__________________
Haz la guerra en la cama y el amor donde se te de la gana...
El tiempo es el mejor maestro, lo único malo es que te mata...¡¡Aprovecha tu tiempo!!
  #4 (permalink)  
Antiguo 25/07/2004, 13:01
 
Fecha de Ingreso: julio-2004
Mensajes: 11
Antigüedad: 20 años, 9 meses
Puntos: 0
Exclamación No coinciden los tipos de dato.

Pues mira, como no proporcionas ni el tipo de error, ni la linea, ni nada, por el momento solo te puedo decir que tienes un error en la linea:

Código:
conn.Execute "INSERT INTO ratings(rating, ip, cdId) VALUES(" & rating & ", '" & visitorIP & "', " & cdId & ")"
ya que segun la tabla "ratings" que describes al final, el campo ip es numérico, y tú lo estas tratando de meter como texto. Pruebalo así:

Código:
conn.Execute "INSERT INTO ratings(rating, ip, cdId) VALUES(" & rating & ", " & visitorIP & ", " & cdId & ")"
sin las comillas simples.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:01.