rsasalm
01-29-2003, 03:02 PM
Hi all
I have some problem with ASP script.
If someone can help me to point out what I am doing wrong.
Below you can see the code.
It works as follow:
When one click on "Add a customer" button with all fields filled with text, alert
dialogs appear with the text filled in the field and it seems to work fine.
Then I try to open a mySQL database and insert a row with data.
But the alert dialog with text "New customer inserted" never pops up which means
that there is some syntax problem with the statement to open and insert inta
the database. Kan some trace out what is wrong with these line of code.
I have one more question:
As you see that my "myfunction" is written and called in Javascript language.
What changes do I need if the same code for "myfunction" is written in VB and
how to call when "Add a customer" is pressed?
Thanks in advance for your help
regards
/rsasalm
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>
<title>init.asp</title>
<script type="text/javascript">
<!--
function myfunction()
{
var name, email, tel, rabbid, pwd, DBConn;
name = document.forms[0].elements[0].value;
email = document.forms[0].elements[1].value;
tel = document.forms[0].elements[2].value;
rabbid = document.forms[0].elements[3].value;
pwd = document.forms[0].elements[4].value;
alert("HELLO");
DBConn = Server.CreateObject("ADODB.Connection");
DBConn.open ("Shop");
DBConn.Execute("insert into tblcustomer values (1,'mosa','mosa@xyz.com','00-123456',1,'mosa')");
alert("New customer inserted");
}
//-->
</script>
</head>
<H1> Register a new customer</H1>
<form >
<table border="4">
<tr>
<td>
Namn:</td>
<td> <input type="text" name="Name"> </td>
</tr>
<tr>
<td>
Email:</td>
<td> <input type="text" name="Email"> </td>
</tr>
<tr>
<td>
Telefonnummer:</td>
<td> <input type="text" name="Telefon"> </td>
</tr>
<tr>
<td>
Rabattgroup:</td>
<td>
<select>
<option value ="professional">professional
<option value ="Student">Student
<option value ="unemployed">unemployed
</select>
</td>
</tr>
<tr>
<td>
Password:</td>
<td> <input type="password" name="Password"> </td>
</tr>
</table>
</br>
<!--<input type="submit" onsubmit/>-->
<input type="submit" name="B1" value="Add a customer">
<input type="reset" onreset/>
</form>
</br>
<script type="text/javascript">
<!--
document.forms[0].onsubmit = myfunction;
//-->
</script>
</body>
</html>
I have some problem with ASP script.
If someone can help me to point out what I am doing wrong.
Below you can see the code.
It works as follow:
When one click on "Add a customer" button with all fields filled with text, alert
dialogs appear with the text filled in the field and it seems to work fine.
Then I try to open a mySQL database and insert a row with data.
But the alert dialog with text "New customer inserted" never pops up which means
that there is some syntax problem with the statement to open and insert inta
the database. Kan some trace out what is wrong with these line of code.
I have one more question:
As you see that my "myfunction" is written and called in Javascript language.
What changes do I need if the same code for "myfunction" is written in VB and
how to call when "Add a customer" is pressed?
Thanks in advance for your help
regards
/rsasalm
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>
<title>init.asp</title>
<script type="text/javascript">
<!--
function myfunction()
{
var name, email, tel, rabbid, pwd, DBConn;
name = document.forms[0].elements[0].value;
email = document.forms[0].elements[1].value;
tel = document.forms[0].elements[2].value;
rabbid = document.forms[0].elements[3].value;
pwd = document.forms[0].elements[4].value;
alert("HELLO");
DBConn = Server.CreateObject("ADODB.Connection");
DBConn.open ("Shop");
DBConn.Execute("insert into tblcustomer values (1,'mosa','mosa@xyz.com','00-123456',1,'mosa')");
alert("New customer inserted");
}
//-->
</script>
</head>
<H1> Register a new customer</H1>
<form >
<table border="4">
<tr>
<td>
Namn:</td>
<td> <input type="text" name="Name"> </td>
</tr>
<tr>
<td>
Email:</td>
<td> <input type="text" name="Email"> </td>
</tr>
<tr>
<td>
Telefonnummer:</td>
<td> <input type="text" name="Telefon"> </td>
</tr>
<tr>
<td>
Rabattgroup:</td>
<td>
<select>
<option value ="professional">professional
<option value ="Student">Student
<option value ="unemployed">unemployed
</select>
</td>
</tr>
<tr>
<td>
Password:</td>
<td> <input type="password" name="Password"> </td>
</tr>
</table>
</br>
<!--<input type="submit" onsubmit/>-->
<input type="submit" name="B1" value="Add a customer">
<input type="reset" onreset/>
</form>
</br>
<script type="text/javascript">
<!--
document.forms[0].onsubmit = myfunction;
//-->
</script>
</body>
</html>