IBM developerWorks
           ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old September 30th, 2003, 08:59 PM
Jeremy2845 Jeremy2845 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 Jeremy2845 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help using forms to update mysql database

I'm trying to take in user input into textfeilds and input it into my MySQL database. Im using ASP. This is what I got, im not seeing and records appear in the database.

<%
on error resume next
dim adoConn
dim strQuery
set adoConn = Server.CreateObject("ADODB.Connection")

adoConn.Open "Driver={mySQL}; Server=blah.com; Port=3306; Option=0; Socket=; Stmt=; Database=inventory; Uid=sa; Pwd=sa;"

if adoConn.errors.count = 0 then
response.write "<h2>connected</h2>"
else
response.write "ERROR: Couldn't connect to database"
end if

strQuery = "INSERT INTO computer(NAME) VALUES"
dim strName

%>


<form action="inventory_form_jeremy.asp" onSubmit="<% adoConn.Execute strQuery %>" method="POST">

Name: <input type="text" name="name" id="name">

<% strName = Request.form("name")
strQuery = strQuery & "('" & strName & "')" %>
</form>

My SQL statement works, only if I hardcode the statement after I connect to the database, not with the user input. That narrows it down to my execute query statement(I think) Any ideas?

Thank you,
Jeremy

Reply With Quote
  #2  
Old September 30th, 2003, 11:00 PM
christo's Avatar
christo christo is offline
Introspective
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Nov 2001
Location: London, UK
Posts: 3,296 christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level)christo User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 1 h 5 m 42 sec
Reputation Power: 101
Send a message via ICQ to christo Send a message via Yahoo to christo
If the query works when you hard code the line in and run, then the problem would appear to be in your use of ASP to build the query dynamically. I have moved this to the ASP forum, where you're more likely to get help with this code.

I would suggest that you construct the query, and then just display it on the screen to the user. You can then visually inspect it or cut and paste it into a mysql dialoge and get the full error message.

christo

Reply With Quote
  #3  
Old September 30th, 2003, 11:33 PM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 6 m 22 sec
Reputation Power: 76
So you don't get any error, but no records are inserted? Or are empty records inserted? Or do you get an error?
The way you have the form and handler setup is rather strange to me. What is the name of your form? Are you having the form submit to itself?
I would separate the form (call it "myForm.asp" or something) from the form handler ("myHandler.asp"). Then take
Code:
<form name ="myForm.asp" action="myHandler.asp" method="POST">

Name: <input type="text" name="name" id="name">

</form>
as its own page (the form) and put your asp in the separate form handler page. Then proceed as before, but now you don't have to concatenate your sql query, and you can easily do whatever you want with the data passed from the form. (I would recommend putting it all in variables, which you can then use). HTH
__________________
--Dave--

U2kgSG9jIExlZ2VyZSBTY2lzLCBOaW1pdW0gRXJ1ZGl0aW9uaXMgSGFiZXM=

Reply With Quote
  #4  
Old September 30th, 2003, 11:49 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,719 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 50 m 18 sec
Reputation Power: 688
Take out the "on error resume next" so you can see what errors you are getting. If you use IE also go to Tools - Internet Options - Advanced Options and uncheck the "show friendly http errors" setting.

Look around in this area of the manual for some examples of ADO usage of the MyODBC drivers.

http://www.mysql.com/products/myodb...or_ODBC_With_VB

You must install MyODBC on the web server.

Reply With Quote
  #5  
Old October 1st, 2003, 07:10 AM
Jeremy2845 Jeremy2845 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 Jeremy2845 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I guess i could use two pages, one form and another handler. I was just trying to do it all in one shot. So when my handler is passed the form, how do I call back for the textfield variables? i guess thats an ASP question, i'll try the other form also.

Reply With Quote
  #6  
Old October 1st, 2003, 07:32 AM
Jeremy2845 Jeremy2845 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 7 Jeremy2845 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I am in the right form...haha
I have my two pages set up and the connection works, I just need to figure out how to reference those textfield variables from this page. Im not sure if its anything like PHP, where you go $_POST(variable).

Thanks

Reply With Quote
  #7  
Old October 1st, 2003, 12:39 PM
karsh44's Avatar
karsh44 karsh44 is offline
Just another guy
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2003
Location: Wisconsin
Posts: 2,915 karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level)karsh44 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 13 h 6 m 22 sec
Reputation Power: 76
To get your values from the form, you would do
Code:
dim myVariable
myVariable=Request.form("textfieldname")
Then you can use "myVariable" where you need the contents of the text field.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > help using forms to update mysql database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway