Why are Images repeating in Classic ASP - sql

I am currently having a problem with some thumbnail images in a classic ASP website. Essentially, I have a database in Microsoft Access that contains three tables: One with the pictures and their info, another that is linked to the pictures table and contains location information and a third table which just has some text for the website.
On the page which is coded below, each image in the database has its corresponding thumbnail printed onto the page. The user can then click on the thumbnail and be taken to the larger image with some associated information.
My problem is that the thumbnails are repeating themselves, up to 11 times.
<% option explicit %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Places</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- #include file="conn.asp" -->
<div id="container">
<!-- #include file="nav.asp" -->
<% dim SQL, info
' 0 1 2 3 4
SQL = "select PicturesTable.id, filename, location, title, description"&_
" from PicturesTable, locationsTable"&_
" where PicturesTable.locationNum = locationsTable.id"&_
" order by locationsTable.id"
set info=conn.execute(SQL)
This is my loop where I think the problem is.
if info.eof then
response.write "No data found."
end if
do until info.eof
response.write "<a href=""images.asp?i=" & info(1) & """>" &_
"<img src=""thumbs/" & info(1) & """></a>"
info.movenext
loop
%>
</div>
<%
conn.close
%>
</body>
</html>

So the problem was in fact that I had designed the database poorly in access and I was repeating the records when they should have been unique. Hence, the repeated images. Deleting the repeated records gave me the solution. Thanks for the help anyway.

Try the following SQL instead; the problem is likely that you need to JOIN the two tables.
SQL = "SELECT PicturesTable.id, filename, location, title, description"&_
" FROM PicturesTable"&_
" LEFT JOIN locationsTable"&_
" ON PicturesTable.locationNum = locationsTable.id"&_
" ORDER BY locationsTable.id

Related

My delete statement is not working (using oracle 11g)

My delete statement is not working i am trying to delete duplicate row if user have entered more than one product_id and user_id but the delete is not working at all.
I tried entering one row multiple time and hasNext returns true, goes over if but doesn't execute delete and alert
Code:
<%--
Document : cart
Created on : Apr 24, 2020, 3:43:01 PM
Author : user
--%>
<%#page import="java.sql.CallableStatement"%>
<%#page import="java.sql.SQLException"%>
<%#page import="java.sql.ResultSet"%>
<%#page import="java.sql.DriverManager"%>
<%#page import="java.sql.Statement"%>
<%#page import="java.sql.Connection"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String username=(String)session.getAttribute("username");
String product_id=request.getParameter("id");
Connection con=null;
Statement stmt=null;
Statement stmt1=null;
Statement stmt2=null;
try{
Class.forName("oracle.jdbc.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:#localhost:1521:XE","admin","admin");
}
catch(ClassNotFoundException e){
System.out.println("Class not found :"+e.getMessage());
}
try{
int user_id=0;
stmt=con.createStatement();
stmt1=con.createStatement();
stmt2=con.createStatement();
//check for duplicate rows to avoid user adding to cart the same item again.
ResultSet rs=stmt.executeQuery("SELECT user_id FROM users where user_name='"+username+"'");
while(rs.next()){
user_id=Integer.valueOf(rs.getString(1));
System.out.println(user_id);
}
stmt1.executeUpdate("INSERT INTO transaction (user_id,product_id) values('"+user_id+"','"+product_id+"')");
ResultSet rs_check=stmt.executeQuery("SELECT '"+user_id+"','"+product_id+"', COUNT(*) occurences from transaction GROUP BY '"+user_id+"','"+product_id+"' HAVING COUNT(*) > 1 ");
//check for duplicate rows after insert and then delete that row
System.out.println(rs_check.next());//1)false
boolean hasNext=rs_check.next();
if(hasNext){
//stmt2.executeUpdate("delete from transaction where user_id='"+user_id+"' and product_id='"+product_id+"'");
CallableStatement ctmt=con.prepareCall("{call delete_dup(?,?)}");
ctmt.setInt(1,user_id);
ctmt.setInt(2,Integer.valueOf(product_id));
ctmt.execute();
%><script>alert("you have added the item before?");</script><%
}
}
catch(SQLException e){
System.out.println("SQL Exception: "+e.getMessage());
}
%>
</body>
</html>
Try to add a commit after the insert to check if this works like :
con.commit();
If this solve the problem you have to set : con.setAutoCommit(true);, if you don't want to use Oracle commit/rollback feature.

SQL data not showing two columns on site

I've got a DB connection to my SQL Server on Azure. Two columns are showing on the page but not showing the other 2. Columns are company name and further details
Company Name is standard business name
Further Details stores URLs to more information
I've tried the SQL statement in SQL Management and it displays data what should be shown.
I've checked the parameters of the column, they're both nvarchar(Max) it shows as -1 when clicking to modify the size of the column. Does this mean it has unlimited size?
The file type is Classic ASP with inline CSS and HTML inside.
Below is what is being called in the database.
<%
Session.LCID=2057
Dim connpiudb, rspiudata, strSQL, fldThis, strSQL2, strSQL3, strcategory
strcategory = Request.querystring("category")
Set connpiudb = Server.CreateObject("ADODB.Connection")
Set rspiudata = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT companyname, courtnumber, cronumber, furtherdetails FROM piudata WHERE category LIKE '" & strCategory & "%' Order by companyname"
strValue = Request.QueryString(<%= rspiudata.Fields("companyname") %>)
response.write strSQL
response.write strValue
<!-- strSQL = "SELECT companyname , courtnumber , cronumber, furtherdetails FROM piudata WHERE category LIKE '%c%' Order by companyname" -->
connpiudb.Open strConnect
rspiudata.open strSQL, connpiudb
%>
Below is how the database is stored in the HTML table.
<!--content start-->
<FONT FACE="Arial" size="2">
<TABLE BORDER="0" cellpadding="2" width="60%"><TR>
<%
Do Until rspiudata.EOF
%>
<TR><TD width="40%"><B>Company Name:</B></TD><TD width="60%"><%= rspiudata.Fields("companyname") %></TD></TR>
<TR><TD width="40%"><B>Further Details:</B></TD><TD width="60%"><%=rspiudata.Fields("furtherdetails") %></TD></TR>
<TR><TD width="40%"><B>Court Number:</B></TD><TD width="60%"><%= rspiudata.Fields("courtnumber") %></TD></TR>
<TR><TD width="40%"><B>Company Registered Number:</B></TD><TD width="60%"><%= rspiudata.Fields("cronumber") %></TD></TR>
<TR><TD width="100%" colspan="2"><HR></TD></TR>
<%
rspiudata.movenext
Loop
rspiudata.Close
Set rspiudata = Nothing
connpiudb.close
%>
</TABLE>
I am struggling to understand what the actual issue is. Only thing I've thought of is that the columns sizes default to -1 when setting it as MAX or that Classic ASP does not support NVARCHAR(max)
Any help will be great.
Before going further on this, following code needs to be corrected
<%
...
strValue = Request.QueryString(<%= rspiudata.Fields("companyname") %>)
I understood you have it for debug purposes however it has neither valid syntax (you inject <% %> within existing server code block nor valid operator (Request.QueryString is for query strings) nor right place (recordset is defined but not opened).
And read about sql injections.

Response.Write Horizontal Table from SQL Query using Dataview

Still need help, no answer that has worked yet. Please jump in if you have any ideas.
I have been trying to get my Response.Write to go Horizontal, however I cannot seem to figure it out.
This is what I currently have (it all sits within a table) and loads from an sql database query using Dataview to get the vehicles I want to display:
Response.Write("<tr><td width='200px' colspan='3'><a href='car.aspx?invno=" & invno & "'><image runat='server' src='" + imageurl + "'></image></a></td></tr>")
Response.Write("<tr><td width='5px'>" + year + "</td><td width='10px'>" + make + "</td><td width='100px'>" + model + "</td></tr>")
Response.Write("<tr><td width='200px' colspan='3'>" + mileage + "</td></tr>")
However it is Currently giving me this Picture 1
But what I really want is this Picture 2
Any help would be greatly appreciated
Update
Ok so I am editing this whole post, as it was overly complicated with what I want. So I am breaking it down to its simplest:
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource runat="server" id="sqldata" ConnectionString="<%$ ConnectionStrings:cars %>" SelectCommand="SELECT TOP 3 ORDER BY NEWID() )">
</asp:SqlDataSource>
<asp:Panel ID="Panel1" runat="server">
<div style="font-size: 10px; font-family: 'arial';">
<center>
<table id="list" border="0" cellpadding="2" cellspacing="0" width="200px">
<%
Dim dv As Data.DataView = CType(sqldata.Select(DataSourceSelectArguments.Empty), Data.DataView)
For Each dr As Data.DataRow In dv.Table.Rows
Dim make As String = dr("make")
Response.Write("<tr><td>" + make + "</td></tr>")
Next
%>
</table>
</center>
</div>
</asp:Panel>
</form>
</body>
</html>
So with the code above.. I get a vertical list
Ford
Chevy
Toyota
But what I want is a Horizontal list
Ford Chevy Toyota
Create a single row with 3 different columns to achieve your desired result
Response.Write("<tr><td width='200px' colspan='3'><a href='car.aspx?invno=" & invno & "'><image runat='server' src='" + imageurl + "'></image></a></td>")
Response.Write("<td width='5px'>" + year + "</td><td width='10px'>" + make + "</td><td width='100px'>" + model + "</td>")
Response.Write("<td width='200px' colspan='3'>" + mileage + "</td></tr>")

Dreamweaver ASP command INSERT INTO not passing value

Hi I am trying to create an INSERT INTO script in Dreamweaver Command and ASP.
If I use a static value it works fine, but when I try to declare a variable I get the following error message
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Sybase][ODBC Driver][Adaptive Server Anywhere]Primary key for table 'testing'
is not unique
/coding/Untitled-3.asp, line 30
Now the reason it is telling me the primary key is not unique is it is passing a null value, rather than the value of my field. Code below;
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim Command1__product
Command1__product = Request.Form("product")
%>
<!--#include file="Connections/Conn_PSCRM_Demo.asp" -->
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
Set Command1 = Server.CreateObject ("ADODB.Command")
Command1.ActiveConnection = MM_Conn_PSCRM_Demo_STRING
Command1.CommandText = "INSERT INTO testing (prodref) VALUES (?)"
Command1.Parameters.Append Command1.CreateParameter("product", 201, 1, 25, MM_IIF(Request.Form("Field1") , Request.Form("Field1") , Command1__product & ""))
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post" name="form" id="form">
<label for="Field1"></label>
<input name="Field1" type="text" id="Field1" value="33399">
</form>
</body>
</html>
According to my comment - you'll have to check if your form has been posted or your site has just been initially loaded. In your question the code will be executed everytime the site has been loaded - that's why it works when you provide hardcoded values.
Anything like this code will do the trick
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
If Request.Form("SUBMITBUTTON") <> "" then
Dim Command1__product
Command1__product = Request.Form("product")
' all your code goes here!
%>
Bit of a rookie error, I wasn't declaring the form variable.
I have added a Bindings Request.Form and all is working.

ASP.NET Database error

I am trying to follow a tutorial online and I have followed the steps exactly however i keep getting an error when trying to write to a database.
Here Is the code for a simple form
#{
var name = string.Empty;
var email = string.Empty;
var subject = string.Empty;
var message = string.Empty;
if (IsPost){
name = Request["txtName"];
email = Request["txtEmail"];
subject = Request["txtSubject"];
message = Request["txtMessage"];
var db = Database.Open("FormAndDataDB");
db.Execute("INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent) " +
"VALUES (#0, #1, #2, #3, #4)", name, email, subject, message, DateTime.Now);
}
}
<doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<form action="contact.cshtml" method="POST">
<p>
<label for="txtName">Name:</label><br />
<input type="text" name="txtName" id="txtName" value="#name"/>
</p>
<p>
<label for="txtEmail">Email:</label><br />
<input type="text" name="txtEmail" id="txtEmail" value="#email" />
</p>
<p>
<label for="txtSubject">Subject:</label><br />
<input type="text" name="txtSubject" id="txtSubject" value="#subject" />
</p>
<p>
<label for="txtMessage">Message:</label><br />
<textarea name="txtMessage" id="txtMessage" cols="40" rows="10" >#message</textarea>
</p>
<p>
<input type="submit" value="send" />
</p>
</form>
</body>
</html>
Here is the error i get in visual studio on attempt of execution of the SQL insert statement:
"An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll but was not handled in user code"
This is the error text returned from SQL and displayed on the webpage:
"The column cannot contain null values. [ Column name = ID,Table name = ContactLog ]"
I have filled out the form completely
Your errors in the question notwithstanding, the problem seems to be that you've got a table (contactLog) with a column (id) that has the NOT NULL attribute attached to it. You are trying to insert a row without a value in said column, and that is causing this error.
To fix this either insert a value into the [ID] column or set the identity attribute to TRUE instead of FALSE on said column and allow it to autogenerate / autoincrement.
My assumption is that even when you fixed the syntax of the insert statement you still couldn't process the insert properly.
You have five columns, but only 3 values.
Your statement is
INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent)
VALUES (#0, #1, #3)
What happened to #2 and #4?
Maybe you need
db.Execute("INSERT INTO ContactLog (Name, Email, Subject, Message, DateSent) "+
"VALUES (#0, #1, #2, #3, #4)",
name, email, subject, message, DateTime.Now);