Hi all, i need help on asp-sql code.
I have a form when I catch some infos and i want to create a new record into a database.
I have tried many syntax but I can't pass the variables a,b,c,d,e,f to sql string.
Please tell me how can i do it.

<%
a=Request.Form("LastName");
b=Request.Form("FirstName");
c=Request.Form("Street");
d=Request.Form("City");
e=Request.Form("Country");
f=Request.Form("Phone");
Response.write (a+" "+b+" "+c+" "+d+" "+e+" "+f);
var sSQLString;
sSQLString = "INSERT INTO tAuthors (LastName, FirstName, Street, City, Country, Phone) VALUES (a,b,c,d,e,f);"
con.Execute(sSQLString);
%>

Thanks in advance, Roby.

Recommended Answers

All 3 Replies

Ok, first I am going to assume that you have the code for the connection "con" somewhere else and this is just a snippet of what you have.

Secondly, why the 'var' and semicolon syntax? Are you writing this in JScript?

Your problem is that you are including a, b, c, d, e, f into a string literal. As such, they are letters, not variables. You need to concatenate them into the string.

Try this...(in VBScript)

<%
Dim a, b, c, d, e, f
Dim sSQLString

a=Request.Form("LastName")
b=Request.Form("FirstName")
c=Request.Form("Street")
d=Request.Form("City")
e=Request.Form("Country")
f=Request.Form("Phone")

Response.write (a & " " & b & " " & c & " " & d & " " & e & " " & f)

sSQLString = "INSERT INTO tAuthors (LastName, FirstName, Street, City, Country, Phone) VALUES (" & a & ", " & b & ", " & c & ", " & d & ", " & e & ", " & f & ")"

con.Execute(sSQLString)
%>
<% @LANGUAGE="JavaScript" %>
<!--#include file="adojavas.inc"-->
<%
var con;
var conString;
con = Server.CreateObject("ADODB.Connection");
conString = "Provider=Microsoft.Jet.OLEDB.4.0; "+ "Data Source= " + Server.MapPath("/public/booksDB.mdb");
con.Open(conString);
%>
<%
a=Request.Form("LastName");
b=Request.Form("FirstName");
c=Request.Form("Street");
d=Request.Form("City");
e=Request.Form("Country");
f=Request.Form("Phone");
Response.write (a+" "+b+" "+c+" "+d+" "+e+" "+f);
var sSQLString;
sSQLString = "INSERT INTO tAuthors (LastName, FirstName, Street, City, Country, Phone) VALUES (a,b,c,d,e,f);"
con.Execute(sSQLString);
%>
<%
con.Close( );
con = null;
%>

This is my full code for this asp-javascript page.
The problem with the code you suggest me is that it isn't Javascript like and I need Javascript.

I really appreciate your help, but if you can help me with a javascript like code I thank you for ever :)

I have resolved the question.
With your code, a good vbscript to javascript translator and some adjustment it works fine.

this is the final code (the part that give problem before).

sSQLString = "INSERT INTO tAuthors (LastName, FirstName, Street, City, Country, Phone) VALUES ('" + a + "', '" + b + "','" + c + "', '" + d + "' , '" + e + "' , '" + f + "');"

Thanks all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.