| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

02-21-05, 09:35
|
|
Registered User
|
|
Join Date: Dec 2003
Location: Colorado
Posts: 12
|
|
|
asp into mysql
|
|
All,
I am new to all this, so please be patient with me. I have established a connection with my MySQL database using ASP, but now I want to get data into the database via an .asp form.
The connection code I have inside regForm.asp is:
<%
ConnString = "Driver={MySQL};SERVER=localhost;DATABASE=database name;UID=uid;PASSWORD=password"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnString
%>
What do I need to do to have data populate the MySQL table when the submit button on the form is clicked?
I guess I need to code to add a new record to my table in mysql. Can someone please help with the code for this?
I have replaced the actual real info in the code above with generic stuff.
Please help.
Thanks in advance,
|
|

02-22-05, 06:09
|
|
Registered User
|
|
Join Date: Feb 2005
Location: London
Posts: 19
|
|
In your submit_Form.Asp
you have to open database connection and execute INSERT query on it..
for example,
Dim Conn, insertSQL
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open connectionString
If Conn.State = 1 Then
insertSQL = "INSERT INTO tableXYZ VALUES (" & var1 &", " & var2 & ")"
Conn.Execute insertSQL
Conn.Close
End If
Set Conn = Nothing
Hope this will help...
|
|

02-23-05, 01:15
|
|
Registered User
|
|
Join Date: Dec 2003
Location: Colorado
Posts: 12
|
|
|
|
jay82,
This is the code I ended up using:
<%
ConnString = "Driver={MySQL};SERVER=localhost;DATABASE=gsgevent s;UID=gsgevents;PASSWORD=mollycollie"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnString
mySQL = "INSERT INTO tbl_registration (dateEntered,salutation,first_lastName,company,mai lingAddress,city,state,zipCode,telephoneNo,faxNo,e mailAddress,xMeal,hotelYesNo,arrivalDate,departure Date,roomType,bedSize,sharingRoomYesNo,roomMate,to talInRoom,creditCardType,creditCardNo,cardHoldersN ame,expDate)"
mySQL = mySQL & " VALUES ('" & request.form("dateEntered") & "','" & request.form("salutation") & "','" & request.form("first_lastName") & "','" & request.form("company") & "','" & request.form("mailingAddress") & "','" & request.form("city") & "','" & request.form("state") & "','" & request.form("zipCode") & "','" & request.form("telephoneNo") & "','" & request.form("faxNo") & "','" & request.form("emailAddress") & "','" & request.form("xMeal") & "','" & request.form("hotelYesNo") & "','" & request.form("arrivalDate") & "','" & request.form("departureDate") & "','" & request.form("roomType") & "','" & request.form("bedSize") & "','" & request.form("sharingRoomYesNo") & "','" & request.form("roomMate") & "','" & request.form("totalInRoom") & "','" & request.form("creditCardType") & "','" & request.form("creditCardNo") & "','" & request.form("cardHoldersName") & "','" & request.form("expDate") & "')"
'make sure to change the word "demoConn"
'below to the name of your connection
Conn.execute(mySQL)
%>
It works fine, but now I want to add a piece of code to redirect the user to another page upon clicking the submit button.
How would I do this my friend?
Hope you can help me.
Thanks in advance.
|
|

02-23-05, 07:36
|
|
Registered User
|
|
Join Date: Feb 2005
Location: London
Posts: 19
|
|
You mean after inserting data into table...
that's easy...
you can simply write
Response.Redirect ("/folder/xyz.asp")
and it will redirect to that page after inserting record into your table.
you might want to check error before doing this.. like
If Err.number <> 0 Then
Response.Redirect ("/folder/xyz.asp")
Else
Respone.write "Errror : " & Err.Description
End If
|
|

02-23-05, 09:09
|
|
Registered User
|
|
Join Date: Dec 2003
Location: Colorado
Posts: 12
|
|
The only problem with that, is if I hit the Refresh button it redirects also, and I don't want that.
How do I stop it from redirecting if the Refresh button is depressed?
|
|

02-23-05, 09:13
|
|
Registered User
|
|
Join Date: Dec 2003
Location: Colorado
Posts: 12
|
|
Also, if my link is chosen to go to the submission form, it right away redirects to the confirmation page. In other words, I can't even get to the submission page, without it automatically redirecting to the confirmation page.
How do I remedy this, along with remedy of the Refresh button?
|
|

02-23-05, 09:41
|
|
Registered User
|
|
Join Date: Dec 2003
Location: Colorado
Posts: 12
|
|
Here is the code with the redirect part. Is that part in the right place?:
<%
ConnString = "Driver={MySQL};SERVER=localhost;DATABASE=gsgevent s;UID=gsgevents;PASSWORD=mollycollie"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnString
mySQL = "INSERT INTO tbl_registration (dateEntered,salutation,first_lastName,company,mai lingAddress,city,state,zipCode,telephoneNo,faxNo,e mailAddress,xMeal,hotelYesNo,arrivalDate,departure Date,roomType,bedSize,sharingRoomYesNo,roomMate,to talInRoom,creditCardType,creditCardNo,cardHoldersN ame,expDate)"
mySQL = mySQL & " VALUES ('" & request.form("dateEntered") & "','" & request.form("salutation") & "','" & request.form("first_lastName") & "','" & request.form("company") & "','" & request.form("mailingAddress") & "','" & request.form("city") & "','" & request.form("state") & "','" & request.form("zipCode") & "','" & request.form("telephoneNo") & "','" & request.form("faxNo") & "','" & request.form("emailAddress") & "','" & request.form("xMeal") & "','" & request.form("hotelYesNo") & "','" & request.form("arrivalDate") & "','" & request.form("departureDate") & "','" & request.form("roomType") & "','" & request.form("bedSize") & "','" & request.form("sharingRoomYesNo") & "','" & request.form("roomMate") & "','" & request.form("totalInRoom") & "','" & request.form("creditCardType") & "','" & request.form("creditCardNo") & "','" & request.form("cardHoldersName") & "','" & request.form("expDate") & "')"
'make sure to change the word "demoConn"
'below to the name of your connection
Conn.execute(mySQL)
Response.Redirect ("http://www.gsgevents.com/secureEvents/confirmation.html")
%>
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|