PDA

View Full Version : ASP: inserting data into database


sirarfalot
11-07-2003, 10:45 AM
Ok, Ive got a form called newband.asp. the fields in that are:
Genre,BandName,URL, influence1,influence2,influence3,influence4, address, email, country, bio.
The database is MS SQL.

Ive written an insert script in asp: called addband.asp

<%
'Gather variables from submitted page
Dim strGenre, strbandname, strURL, strinfluence1, strinfluence2, strinfluence3, strinfluence4, straddy1, strCountry, streaddy1, strbandinfo

strGenre = Request.Form("Genre")
strbandname = Request.Form("bandname")
strURL = Request.Form("URL")
strinfluence1 = Request.Form("influence1")
strinfluence2 = Request.Form("influence2")
strinfluence3 = Request.Form("influence3")
strinfluence4 = Request.Form("influence4")
straddy1 = Request.Form("addy1")
strCountry = Request.Form("Country")
streaddy1 = Request.Form("eaddy1")
strbandinfo = Request.Form("bandinfo")

'Create INSERT statement
'You may need to change the columns in the statement below to match the columns in your table
Dim strSQL, objConn, objCmd
strSQL = "INSERT INTO desabells(Genre, bandname, URL, influence1, influence2, influence3, influence4, addy1, Country, eaddy1, bandinfo) VALUES ("
strSQL = strSQL & "'" & Replace(strGenre,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strBandName,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strURL,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strInfluences1,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strInfluences2,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strInfluences3,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strInfluences4,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strAddress,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strCountry,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strEmail,"'","''") & "',"
strSQL = strSQL & "'" & Replace(strBio,"'","''") & "')"

Dim oConn
Set oConn = Server.CreateObject( "ADODB.Connection" )
oConn.Open "Provider=MSDataShape;" & _
"Data Provider=SQLOLEDB;" & _
"Data Source=JASON;" & _
"Initial Catalog=desabells;" & _
"User ID=JasonMorjaria;" & _
"Password=bubble"


'Create Command Object
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = oConn
objCmd.CommandText = strSQL
'objCmd.Execute


'Remove variables
Set objCmd = nothing
Set objConn = nothing

Response.Redirect "redirect.asp?Bandname=" & request("Bandname") & "&email=" & request("email")
%>



I cannot get the page to work for some reason???????

the error is:
Page cannot be found.


Not sure why?
the page is there. The server is asp enabled, its abyss. Will I need IIS for this script to work.

I dont really know which of my scripts need IIS as I dont have it and am not sure if its a fault in my code or a lack of IIS.

Any help would be appreciated.

thanks

MikeParent
11-07-2003, 01:02 PM
Link?

Did you verify if the data is getting inserted?
Is it crapping out on the addband.asp or the redirect page at the bottom?
Is redirect.asp in the same folder as addband.asp?

sirarfalot
11-07-2003, 02:59 PM
heres the link to the page

www.desabells.com/forms/newband.asp

the data isnt getting put into the database. the redirect was wrong but now fixed.

MikeParent
11-08-2003, 10:58 AM
So are you still getting page not found? I submitted something but didnt get anything except the success page...

sirarfalot
11-10-2003, 02:24 PM
ok, im not getting page not found, im getting sucess page, but its not putting into database, annoying, any ideas?

sirarfalot
11-11-2003, 01:54 PM
Ok, im still not sure why this isn't working. I think the password was correct.

Is there another way of doing it?? Please submit any code that might do something similar!!

MikeParent
11-13-2003, 04:15 AM
Dang, I was sure I responded the other day but my post didnt make it.
Do a response.write of the strSQL var and comment out the response.redirect.
Post back what it returns for strSQL.

PS: Have you tried pulling anything out of the database using that connect object/string?

MikeParent
11-13-2003, 04:23 AM
Just noticed a small discrepancy: the form value for email address is called eaddy1, you assign Request.Form("eaddy1") to streaddy1 but then when you post to the database you refer to "strEmail" which isn't declared. Should that be streaddy1 instead?

PS: If you put an
option explicit
as the *very first* line of your asp code. It forces you to Dim all your variables before you can use them. Helps to catch these sorts of things

kako00000
07-31-2005, 08:36 AM
this site is not open

Terminator1138
08-05-2005, 07:46 AM
Here again its the way of the web, sometimes links stop working after 2 years,....did you notice the dates?