View Full Version : Javascript SQL statement
DangerousDan
December 17th, 2007, 09:21 AM
var SQL = "INSERT INTO wrestlers VALUES (null,'"+name+"', "+t+", "+n4+", "+n3+", "+n2+", "+r+", "+e+", "+p1+", "+p2+", "+pdq+", "+pin+", "+tf+", "+md+", "+d+", "+fft+", "+def+", "+dq+", '"+team+"', "+team_points+")";
rs.Open(SQL, cn);
Everything works fine EXCEPT it doesn't like the null at the start. it's for the ID (Its an auto increment) in the table. Any other way I could put null? If there isn't, I know a simple work around.
Charleh
December 17th, 2007, 09:37 AM
You don't specify the data to insert into an auto increment - just leave out the 1st item and SQL will know what you are doing - otherwise you are specifically trying to insert NULL into the ID column (which SQL will moan about!)
var SQL = "INSERT INTO wrestlers VALUES ('"+name+"', "+t+", "+n4+", "+n3+", "+n2+", "+r+", "+e+", "+p1+", "+p2+", "+pdq+", "+pin+", "+tf+", "+md+", "+d+", "+fft+", "+def+", "+dq+", '"+team+"', "+team_points+")";
rs.Open(SQL, cn);
DangerousDan
December 17th, 2007, 06:34 PM
I thought the same thing, when I tried it was giving me errors! :shifty:
When I get back on the school computer (a day), I'll leave it out again. If it doesn't work I'll just change it to
INSERT INTO wrestlers (name , t, N4...) VALUES(...)
MTsoul
December 17th, 2007, 07:23 PM
I'm not sure how you are doing this with Javascript exactly, but this is a VERY VERY BAD IDEA. That opens up a very obvious security hole. Anyone with a decent browser could edit the Javascript and modify your database in ways outside of your intentions, including DROP table!
simplistik
December 17th, 2007, 09:42 PM
Yea definately avoid doing this w/ javascript. the reason it's done on server-side is cause you can't see it. javascript is client-side and it can be exploited easily.
DangerousDan
December 18th, 2007, 08:09 PM
This is just being used for the wrestling coach at my high school to keep track of his students, I'm not putting this online. I'm using a local Access database rather then an online one. Think of it as an application more then a web site. I'm well aware of the security risks, if I was making one for a website I'd use PHP. :thumb2:
DangerousDan
December 19th, 2007, 07:34 AM
Getting something along the lines of "Number of query fields do not match destination"
I'm going to try the way I mentioned before.:shifty:
EDIT: It worked, although I'm not sure how I'd go about looping through my table in Javascript...
Bmoeb
December 19th, 2007, 09:52 AM
Why not go with an ajax solution? It would be much easier to get support, and You should get the same effect.
You can include php inside your js script. You can just loop through the results with php and append the resulting data to a javascript array.
DangerousDan
December 21st, 2007, 07:35 AM
This is just being used for the wrestling coach at my high school to keep track of his students, I'm not putting this online. I'm using a local Access database rather then an online one. Think of it as an application more then a web site. I'm well aware of the security risks, if I was making one for a website I'd use PHP. :thumb2:
Why not go with an ajax solution? It would be much easier to get support, and You should get the same effect.
You can include php inside your js script. You can just loop through the results with php and append the resulting data to a javascript array.
If I was putting this on the web, I would use PHP. I'm not, I'm using it as an application. :geek:
Anyone know if you can loop through a database with Javascript?
I'm assuming you use While(!file.EoF) or something
borrob
December 21st, 2007, 04:33 PM
the only way this can be done is by serverside javascript and asp.
or visualbasic
if you are using acces then you can create an application in there with forms and visual basic so why javascript?
clientside javascript hasn't got the ability to change data on a computer.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.