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:
  #1  
Old September 2nd, 2003, 11:19 AM
spworld spworld is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 spworld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
insert statement using asp-mysql doesn't work ! help

This is a sample ASP page that didn' t work when I uploaded it.My aim was to insert new record to a simple table called mlist that contains two fields :
- id (auto_number)
- email(text) .
Can anybody find the problem?
--------------------------------------------------------------
also,please I want links to webpages that best help in
asp-mysql,asp-database .
------------------------------------------------------

<html >
<head>
<title>Insert test</title>
</head>
<body >
<%
set myconn = Server.CreateObject("ADODB.connection")
connection = "DRIVER={MySql}; SERVER=localhost; DATABASE=DB-name; UID=user-name; PWD=******"
myconn.open(connection)

set rs = Server.CreateObject("ADODB.recordset")
sql= "INSERT INTO mlist ('id','email') VALUES (3, 'myemail@hotmail.com')"
Set rs= myconn.execute(sql)
rs.close
myconn.close
%>
Your info has successfully been added to the mailing list!
</body>
</html>

Reply With Quote
  #2  
Old September 2nd, 2003, 11:34 AM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
What do you mean by that didn' t work ?

Do you get an error message?
I assume your INSERT didn't work?
Is that correct?

Make a Response.Write of your SQL Query
then copy/paste the result into your database, run the Query see if it works!

If it doesn't then what's the error message it gives you?

You'll need to DEBUG until you find what causes your code not to work!

Everything you've shown seems ok so I don't know what to tell you beside do these steps...

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #3  
Old September 2nd, 2003, 11:41 AM
spworld spworld is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 spworld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks Vlince for replying,
I made a slight change to the code and the record was inserted .However ,after excuting the page,an error page saying that "internal server error" is appeared.In another words, the sentence "Your info has successfully been added to the mailing list! " is not shown! what do you think the reason is?
thanks
in advance

Reply With Quote
  #4  
Old September 2nd, 2003, 12:10 PM
Vlince Vlince is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Canada, Quebec, Montreal
Posts: 410 Vlince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
---BEGIN QUOTE---
what do you think the reason is
---END QUOTE---

I have no clue but the error message says:
internal server error

Try this inside your browser...
Tools-->Internet Options-->Advance(tab)-->then Uncheck Show Friendly HTTP error messages

Make sure it is unchecked, then retry your code.
It should print the exact error message!

Otherwise try adding this at the top of your asp page:
On Error Resume Next

and at the bottom add this:

If Err.number <> 0 Then
Response.Write "Number : " & Err.number & "<br>"
Response.Write "Description : " & Err.Description & "<br>"
Response.Write "Source : " & Err.Source & "<br>"
Response.End
End If


If you decide to go with the second approach remember to remove the On Error Resume Next and comment the If Err.number <> 0 Then stuff once you've corrected the error.

Leaving the On Error Resume Next "on" is evil!!!
Seriously though, comment it otherwise if you do have any other errors it'll simply resume and you don't want that. In fact you want to make sure you code is error free right?

Try the first approach see then what happens!

Hope this helps!
Sincerely

Vlince

Reply With Quote
  #5  
Old September 2nd, 2003, 12:29 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 13 m 21 sec
Reputation Power: 76
To use asp with mySQL, I believe you need the myODBC component installed on your IIS server. Get it at http://www.mysql.com/downloads/api-myodbc.html

Reply With Quote
  #6  
Old September 4th, 2003, 02:54 AM
lafnboy lafnboy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 2 lafnboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hey spworld. I was encountering the same error as you. In fact, your code gave me the inspiration for solving my error.

I think the problem is that an INSERT does not return a recordSet, therefore causing an error when you try to assign the result of the execute(sql) to rs. I did the same thing.

To fix my problem, I simply have the connection do the execute, and then close the connection.

In your code, try changing this block:

set rs = Server.CreateObject("ADODB.recordset")
sql= "INSERT INTO mlist ('id','email') VALUES (3, 'myemail@hotmail.com')"
Set rs= myconn.execute(sql)
rs.close

to:

sql= "INSERT INTO mlist ('id','email') VALUES (3, 'myemail@hotmail.com')"
myconn.execute(sql)

Hope it works for you. And thanks for helping me, indirectly.


Laf

Reply With Quote
  #7  
Old September 4th, 2003, 03:10 AM
spworld spworld is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 20 spworld User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks Laf,
I made the changes and the code worked fine .

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > insert statement using asp-mysql doesn't work ! help


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 4 hosted by Hostway
Stay green...Green IT