Click to See Complete Forum and Search --> : INSERT using dropdown menu
PhilC797
04-27-2004, 08:17 AM
The processing file looks like this :-
<html>
<body>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
Conn.Mode = 3
conn.Open "c:/Inetpub/wwwroot/db1.mdb"
sql="INSERT INTO Players (Player,Pos,Club,Val) VALUES ('" & Request.Form("player") & "','" & Request.Form("position") & "','" & Request.Form("club") & "','" & Request.Form("val") &"')"
conn.Execute sql
conn.close
response.redirect "conf.html"
%>
</body>
</html>
And the form code looks like this :-
<html>
<head>
<script src="useful.js">
</script>
</head>
<body><form name="details" method="post" enctype="text/plain" action="demo_add.asp" onsubmit="return check()">
<table>
<tr>
<td>Player Name:</td>
<td><input name="player"></td>
</tr><tr>
<td>Position:</td>
<td><select name="position">
<option value="GK">GK
<option value="RB">RB
<option value="LB">LB
<option value="CB">CB
<option value="MF">MF
<option value="ST">ST
</select></td>
</tr><tr>
<td>Club:</td>
<td><input name="club"></td>
</tr><tr>
<td>Value:</td>
<td><input name="val"></td>
</tr>
</table>
<br /><br />
<input type="submit" value="Add New">
<input type="reset" value="Clear">
</form>
</body>
</html>
The form works if I leave it as a text box and enter data as it fits into the database, but, even though the text in the dropdown menus is exactly as should be in the database I get a data type mismatch error.
Amyone any ideas??
buntine
04-27-2004, 08:58 AM
Is the data type defined in the Access database set to 'text'? If not, change it.
Also, remove the 'enctype' parameter from your <form> element. It may well be interfering with the data.
Regards,
Andrew Buntine.
PhilC797
04-27-2004, 11:50 AM
ok, the field is defined as text and I have removed the enctype parameter - still no joy. I also removed the name as it is not referred to - still same error!!!
Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.
/demo_add.asp, line 12
Can see how there is a data type mismatch unless there is a different way of reading data from the dropdown menu.
buntine
04-27-2004, 06:05 PM
Weird.. This error normally only pops up when you try to save a blank string within a Date/Time field.
Try some debugging. Just print the value of the select box using Response.write() and seeing if any output is generated.
Regards,
Andrew Buntine.
Alex C
04-27-2004, 09:40 PM
Ah I'm trying to do exactly the same thing as you, well I'm trying to add new rows.
But have you tried placing the Request.Form calls into a variable before you pass them through the SQL command? I'm not sure if that will make a difference but I've always grabed the Form values first before using them like this:
PlayerPlayer = Request.Form("player")
PlayerPosition = Request.Form("position")
PlayerClub = Request.Form("club")
PlayerVal = Request.Form("val")
sql="INSERT INTO Players (Player, Pos, Club, Val) VALUES ('PlayerPlayer', 'PlayerPosition', 'PlayerClub', 'PlayerVal')"
Hope this helps,
Alex.
buntine
04-27-2004, 10:04 PM
The preceding code snipet will generate an error because the variables will be treat as strings..
Regards,
Andrew Buntine.
Alex C
04-27-2004, 11:02 PM
Originally posted by Alex C
Ah I'm trying to do exactly the same thing as you, well I'm trying to add new rows.
But have you tried placing the Request.Form calls into a variable before you pass them through the SQL command? I'm not sure if that will make a difference but I've always grabed the Form values first before using them like this:
PlayerPlayer = Request.Form("player")
PlayerPosition = Request.Form("position")
PlayerClub = Request.Form("club")
PlayerVal = Request.Form("val")
sql="INSERT INTO Players (Player, Pos, Club, Val) VALUES ('PlayerPlayer', 'PlayerPosition', 'PlayerClub', 'PlayerVal')"
Hope this helps,
Alex.
After reading your reply to my post I see why now, thanks! Was taking too much PHP variable useage into play hehe.
buntine
04-27-2004, 11:17 PM
Oh ok, so you've come from a PHP background? The transition can be difficult, there are alot of syntex differences between the two.
Regards,
Andrew Buntine.
Alex C
04-27-2004, 11:29 PM
Originally posted by buntine
Oh ok, so you've come from a PHP background? The transition can be difficult, there are alot of syntex differences between the two.
Regards,
Andrew Buntine.
Lol funnily no, I started out around Vb/Asp but I've been doing much PHP of late that plugging in a Variable without thought for its surroundings was starting to come as second nature ;-\
Hows the whether up in WA?, shes bollocks down here :p
Alex C
04-27-2004, 11:43 PM
Try using the CStr(Request.Form("position")) just to make sure its being posted as a String ;-\
buntine
04-28-2004, 12:00 AM
Its over 30 everyday up here, naturally. ;) Tassie is always cold, man. So is Melbourne -- i just moved from Melb a couple of months ago.
Yes, agreed, good observation. You should use VBScripts data type casting functions on your Request.Form() collection members to ensure Access is treating them correctly.
CStr() for strings
CBool() for booleans (true/false)
CInt() for integers
CLng() for long integers
CDate() for dates.
Theres a few more. Check out www.asp-help.com for them.
Regards,
Andrew Buntine.
Alex C
04-28-2004, 12:36 AM
Tassie born and bread :D Haven't been to WA but the time I was in Darwin it sure was bloody hot!! Lol.
Melbourne is nice in the summer :p
PhilC797
04-28-2004, 09:26 AM
I have tried CStr in the format
& CStr (Request.Form("position")) &
Still showing error!!!!
buntine
04-28-2004, 10:47 AM
Did you try printing each member of the request.form() collection to the screen before you run the SQL query?
This error is normally generated when you try to insert a null string or date.
Regards,
Andrew Buntine.
PhilC797
04-28-2004, 12:05 PM
I'm not entirley sure of the syntax of it. I know response.write outputs to the screen but I'm not sure how to link such variables in!!!
Alex C
04-28-2004, 06:11 PM
Comment out all your ASP code then add this at the top:
PlayerPlayer = CStr(Request.Form("player"))
PlayerPosition = CStr(Request.Form("position"))
PlayerClub = CStr(Request.Form("club"))
PlayerVal = CStr(Request.Form("val"))
Response.Write PlayerPlayer & "<br>" & PlayerPosition & "<br>" & PlayerClub & "<br>" & PlayerVal
Run that and it will display the values of player, position, club and val one under the other. If nothing is displayed then you have a problem either getting the data or posting it. Good luck.
Alex.
PhilC797
04-29-2004, 04:06 AM
The error is still appearing so I must not be commenting out properly!!!!
I have tried /* .. .. */ and <!-- .. .. --> and neither seems to work. I can't find what the tag should be except that VBScript can be commented out using the HTML comment tags.
What do I do??
buntine
04-29-2004, 05:19 AM
Oh, the ASP comment is a single quote. <!-- --> is for html based languages only. The /* */ and // commenting sequences are for C-style languages like C, C++, Java, etc.
'This is a comment.
response.write("This is not")
Check out the following link for some more basic ASP examples www.asp101.com
Most languages will require quite a working knowledge before you can start to write application. I suggest you chekc out some ASP-related web sites or buy a book on the subject.
Regards,
Andrew Buntine.