Javascript and database
-
Hello, does anyone know if it possible to read data from a javascript form and write it into a database (Access for example)? I have an online form that i used with cgi-mail and now i need to save the info on a database, any help would be appreciated... Thanks Rona
-
Hello, does anyone know if it possible to read data from a javascript form and write it into a database (Access for example)? I have an online form that i used with cgi-mail and now i need to save the info on a database, any help would be appreciated... Thanks Rona
JavaScript should never directly communicate with a database because then the user would be able to see the passwords etc for it. What you should do is have it call a PHP/ASP page that will do the database work for it.
Brad Australian By contacting your lawyer you negate the right to sue me.
-
Hello, does anyone know if it possible to read data from a javascript form and write it into a database (Access for example)? I have an online form that i used with cgi-mail and now i need to save the info on a database, any help would be appreciated... Thanks Rona
JavaScript is a scripting language that runs inside the browser and stays inside the browser. JavaScript can't be made to access anything external on the users computer, such as files on the users hard drive, or change settings on the users computer. If it did it would constitute a major security risk. So basically what you're asking is impossible, you can't access a database directly but, as the other poster says, you could do it indirectly via a server side script in ASP/PHP etc, but it would have to be a database on the server and not on the users computer. You could get JavaScript to initiate a page post back, or use Ajax to call a server side ASP.NET page which connects to the database.
Dominic Pettifer Blog: www.dominicpettifer.co.uk
-
Hello, does anyone know if it possible to read data from a javascript form and write it into a database (Access for example)? I have an online form that i used with cgi-mail and now i need to save the info on a database, any help would be appreciated... Thanks Rona
Yes it is possible, but unless you really really really need to (and even if you think you need to you probably don't and you certainly shouldn't) then don't.
var objConn = new ActiveXObject('ADODB.Connection');
var objRs = new ActiveXObject('ADODB.Recordset');objConn.Open(conn_string);
objRs.Open('SELECT * FROM table', objConn, 2, 3);if(!objRs.BOF)
{
objRs.MoveFirst();
while(!objRs.EOF)
{
document.writeln(objRs.Fields("title").Value +'<br/>\n');
objRs.MoveNext();
}
}It will work, but you will have to have extremely low security settings in IE (it will only work in IE). The user will also get a couple of security warnings which you can't get rid of. The above is provided merely as evidence that it is possible, if you haven't got the hint yet then I'll say once more.... please don't use this for anything other then learning. As you're using cgi-mail, you obviously have access to some server-side technology so use that for communicating with your DB. HTH
-
Yes it is possible, but unless you really really really need to (and even if you think you need to you probably don't and you certainly shouldn't) then don't.
var objConn = new ActiveXObject('ADODB.Connection');
var objRs = new ActiveXObject('ADODB.Recordset');objConn.Open(conn_string);
objRs.Open('SELECT * FROM table', objConn, 2, 3);if(!objRs.BOF)
{
objRs.MoveFirst();
while(!objRs.EOF)
{
document.writeln(objRs.Fields("title").Value +'<br/>\n');
objRs.MoveNext();
}
}It will work, but you will have to have extremely low security settings in IE (it will only work in IE). The user will also get a couple of security warnings which you can't get rid of. The above is provided merely as evidence that it is possible, if you haven't got the hint yet then I'll say once more.... please don't use this for anything other then learning. As you're using cgi-mail, you obviously have access to some server-side technology so use that for communicating with your DB. HTH
it will only work in IE
So for all intents and purposes, it doesn't work ;)
Dominic Pettifer Blog: www.dominicpettifer.co.uk