Current location: Hot Scripts Forums » Programming Languages » ASP » Can not insert data to database


Can not insert data to database

Reply
  #1 (permalink)  
Old 07-20-05, 12:05 AM
trod trod is offline
New Member
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Can not insert data to database

Hello,
my problen must be simple but i have not find a way to solve it.
I am using IIS and mysql and i have a database which i retrieve data with the ASP. The problem is that i can not insert data to the database.

The code is simple, i have 3 text boxes and a submit button. The database has 3 fields (name,surname,telephone) I want to enter in the textboxes the data and then to be inserted in the database.

The problem is that i can not insert the variables. If i try to enter
strQuery = "Insert into clientid (name,surname,telephone) Values ('john','mathews','1234')" works fine but i am not sure i know the syntax for entering variables is strQuery = "Insert into clientid (name,surname,telephone) Values ('"a"','"b"','"c"')"? Sorry for the silly question but i have stucked here for 2 days and i can not find an answer.

What is the correct syntax for entering the variables a,b,c (blue color) to the sql query (red color)?

Thank you

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="insert_into.asp" method="post" name="form1" target="_blank">
<p>Name:
<input type="text" value = "<%=a%>" name="textfield1">
</p>
<p>Surname:
<input type="text" name="textfield2">
</p>
<p>Telephone:
<input type="text" name="textfield3">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>


</form>
</body>
</html>


<%
a=request.form ("textfield1")
b=request.form ("textfield2")
c=request.form ("textfield3")

dim conn, sqltext

dim rs

dim counter

dim strquery

set conn = Server.CreateObject("ADODB.Connection")

set rs = Server.CreateObject("ADODB.Recordset")

conn.Open "DSN=hotel"

rs.ActiveConnection = conn

response.write "<h2>Fields In The 'Contacts' Table:</h2>"

rs.Open "Select * From clientid"

while not rs.EOF

response.write rs.fields(0).value & " "
response.write rs.fields(1).value & " "
response.write rs.fields(2).value & "<br>"

rs.MoveNext

wend

strQuery = "Insert into clientid (name,surname,telephone) Values ('"a"','"b"','"c"')"

conn.Execute strQuery

rs.close

%>



ps: the error that i get is Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/insert_into.asp, line 75, column 68
strQuery = "Insert into clientid (name,surname,telephone) Values ('"a"','"b"','"c"')"
Reply With Quote
  #2 (permalink)  
Old 07-20-05, 06:38 AM
minority minority is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
I think your sql statement should be like this

strQuery = "Insert into clientid (name,surname,telephone) Values ("&a&","&b&","&c&")"

If it errors try putting the '' around them again

cheers

Mino
Reply With Quote
  #3 (permalink)  
Old 07-20-05, 07:33 AM
koncept
Guest
 
Posts: n/a
nice job minority, but any string value needs to be enclosed in ' '

so the query should read
strQuery = "Insert into clientid (name,surname,telephone) Values ('" & a & "', '" & b & "','" & c & "')"
Reply With Quote
  #4 (permalink)  
Old 07-20-05, 07:38 AM
minority minority is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
just helping since i always here lol.

I did think that but couldnt remember......so close to showing off
Reply With Quote
  #5 (permalink)  
Old 07-20-05, 07:42 AM
koncept
Guest
 
Posts: n/a
we all start someone, someone shows us the error of our ways and we continue to help others. it was a great start, i still forget to add the single quotes at times.....*tries to hide behind the couch*.
Reply With Quote
  #6 (permalink)  
Old 07-20-05, 08:13 AM
minority minority is offline
Wannabe Coder
 
Join Date: Jun 2005
Posts: 145
Thanks: 0
Thanked 0 Times in 0 Posts
lol....

Ah well we all your help i just getting cocky lol look at what im trying to do in my next script.

Telling you summer vacations suppose to be easy not more stressful than uni.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with Auto Dealer Script nuzzle PHP 17 04-14-10 08:34 PM
Why won't select list item insert into database? gavacho PHP 2 12-05-08 06:38 PM
Pushing data to clients brokennb PHP 2 06-16-05 08:52 PM
Script for uploading data from local database to production database pual_cruzs PHP 1 07-06-04 12:44 AM


All times are GMT -5. The time now is 03:28 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.