Jump to content

Problem inserting a record with a recordset value for one of the fields


javaholic5

Recommended Posts

I'm having problems inserting a value into a record in ms access.I have a recordset object which I passed on to my page and I access it using Request.QueryString.when I try to insert a record, it works, however the field that is supposed to have the Request.QueryString value remains empty.not sure what is going on. My best explanation is that Request.QueryString saves values as UTF-8 and th sql does not by default.

<%dim codedim timedatedim numIncrementdim bkidcode = "BK_"timedate = Day(Date) & Month(Date) & Year(Date) & hour(now) & Minute(now) & Second(now)numIncrement = "44"bkid = code & timedate & "_" & numIncrement%><%If Request.Form("bookeventBtn") <>"" Thensql="INSERT INTO Bookings (booking_id,published_id,user_id,booking_date,booking_time,booking_quantity,booking_payment_type)"sql=sql & " VALUES "sql=sql & "('" & bkid &"','"& Request.QueryString&"','"& Session("userid")&"',"sql=sql & "'" & Date()&"','"& time()&"','"& Request.Form("quantity")&"','"& Request.Form("ptype")&"')"on error resume nextconn.Execute sql,recaffectedif err<>0 then  Response.Write("No update permissions!")else	response.write("Thank you for booking this event. – Your booking ID is: " & bkid)end ifconn.closeend if%>

Can someone please offer some assistance?Thanks

Link to comment
Share on other sites

What data type used for published_id field in database?
The data type is a stringI also have this field as a primary key on the table 'Published' and it would be a foreign key on the table 'Bookings'
Link to comment
Share on other sites

Print out the SQL string so you can see what you're asking the database to do.
Apparently I was giving it the wrong instructions for the first field, thanks for the heads up. I changed the sql string slightly but the problem still persists. The recordset/querystring is being disregarded on the sql string for some reason:
sql="INSERT INTO Bookings (booking_id,published_id,user_id,booking_date,booking_time,booking_quantity,booking_payment_type)"sql=sql & " VALUES "sql=sql & "('" &code& partid &numIncrement&"','"& partid&"','"& Session("userid")&"',"sql=sql & "'" & Date()&"','"& time()&"','"& Request.Form("quantity")&"','"& Request.Form("ptype")&"')"

When I printed the sql string this was the output:----------------(booking_id,published_id,user_id,booking_date,booking_time,booking_quantity,booking_payment_type) VALUES ('BK_45','','0918523','02/06/2011','10:31:57','1','cash') ----------------

Link to comment
Share on other sites

Please test this :

sql="INSERT INTO Bookings (booking_id,published_id,user_id,booking_date,booking_time,booking_quantity,booking_payment_type)"sql=sql & " VALUES "sql=sql & "('" & bkid & "','myTest','" & Session("userid") & "',"sql=sql & "'" & Date() &"','"& time() & "','" & Request.Form("quantity") & "','" & Request.Form("ptype") & "')"sql = replace(sql,"myTest",replace(request.querystring,"'","''")

Link to comment
Share on other sites

Please test this :
sql="INSERT INTO Bookings (booking_id,published_id,user_id,booking_date,booking_time,booking_quantity,booking_payment_type)"sql=sql & " VALUES "sql=sql & "('" & bkid & "','myTest','" & Session("userid") & "',"sql=sql & "'" & Date() &"','"& time() & "','" & Request.Form("quantity") & "','" & Request.Form("ptype") & "')"sql = replace(sql,"myTest",replace(request.querystring,"'","''")

Hi, tried it but I get an error:
An error occurred on the server when processing the URL. Please contact the system administrator.If you are the system administrator please click here to find out more about this error.
Link to comment
Share on other sites

Hi, tried it but I get an error:
Go to the advanced options of your Internet Explorer and disable the "Show user friendly error messages" option, then try your page again, and see if it gives you a more specific error.
Link to comment
Share on other sites

Go to the advanced options of your Internet Explorer and disable the "Show user friendly error messages" option, then try your page again, and see if it gives you a more specific error.
I am using IIS7 which does not display error messages to the browser by default. However I did configure it to allow it.
Link to comment
Share on other sites

I decided to use an HTML DOM hidden object which would hold the recordset with the published_id value and then reference the hidden field using Request.Form(). It worked....

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...