|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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> |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
---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 |
|
#5
|
||||
|
||||
|
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
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
Thanks Laf,
I made the changes and the code worked fine . |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > insert statement using asp-mysql doesn't work ! help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|