User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP section within the Web Development category of DaniWeb, a massive community of 361,950 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,588 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP advertiser: Lunarpages ASP Web Hosting
Views: 1010 | Replies: 3 | Solved
Reply
Join Date: Mar 2007
Posts: 13
Reputation: roby4eldiablo is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
roby4eldiablo roby4eldiablo is offline Offline
Newbie Poster

Insert Request.Form result into SQL

  #1  
Apr 4th, 2008
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.

  1. <%
  2. a=Request.Form("LastName");
  3. b=Request.Form("FirstName");
  4. c=Request.Form("Street");
  5. d=Request.Form("City");
  6. e=Request.Form("Country");
  7. f=Request.Form("Phone");
  8. Response.write (a+" "+b+" "+c+" "+d+" "+e+" "+f);
  9. var sSQLString;
  10. sSQLString = "INSERT INTO tAuthors (LastName, FirstName, Street, City, Country, Phone) VALUES (a,b,c,d,e,f);"
  11. con.Execute(sSQLString);
  12. %>

Thanks in advance, Roby.
Last edited by peter_budo : Apr 4th, 2008 at 2:33 pm. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 20
Reputation: techtix is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
techtix techtix is offline Offline
Newbie Poster

Re: Insert Request.Form result into SQL

  #2  
Apr 4th, 2008
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)
%>
Reply With Quote  
Join Date: Mar 2007
Posts: 13
Reputation: roby4eldiablo is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
roby4eldiablo roby4eldiablo is offline Offline
Newbie Poster

Re: Insert Request.Form result into SQL

  #3  
Apr 5th, 2008
<% @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
Last edited by roby4eldiablo : Apr 5th, 2008 at 3:30 am.
Reply With Quote  
Join Date: Mar 2007
Posts: 13
Reputation: roby4eldiablo is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
roby4eldiablo roby4eldiablo is offline Offline
Newbie Poster

Re: Insert Request.Form result into SQL

  #4  
Apr 5th, 2008
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP Forum

All times are GMT -4. The time now is 11:52 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC