Jump to content
dhruv.meksha

i can edit my database using javascript in html with sql syntax

Recommended Posts

<title>Edit_Page</title></head><body><form id="frm2" name="frm2" method="post" action=" "><fieldset><legend align="center">Edit Student Info</legend><table align="center" border="0"><tr> <td>ID:</td> <td><input type="text" id="txtId" name="txtId" /></td></tr><tr> <td>First Name:</td> <td><input type="text" id="txtFname" name="txtFname" /></td></tr><tr> <td>Last Name:</td> <td><input type="text" id="txtLname" name="txtLname" /></td></tr><tr> <td>Address:</td> <td><textarea id="txtAddress" name="txtAddress" cols="30" rows="3"></textarea></td></tr><tr> <td>Pincode:</td> <td><input type="text" id="txtPin" name="txtPin" /></td></tr><tr> <td>Mobile No.:</td> <td><input type="text" id="txtMob" name="txtMob" /></td></tr><tr> <td>Mail ID:</td> <td><input type="text" id="txtMail" name="txtMail" /></td></tr><tr> <td><input type="button" id="btnUpdate" name="btnUpdate" value="Update" onclick="update();" /></td></tr></table></fieldset></form></body><script type="text/javascript">function update(){ var id=document.getElementById('txtId'); alert(id.value); var fname = document.getElementById('txtFname'); alert(fname.value); var lname = document.getElementById('txtLname'); alert(lname.value); var address = document.getElementById('txtAddress'); alert(address.value); var pin = document.getElementById('txtPin'); alert(pin.value); var mob = document.getElementById('txtMob'); alert(mob.value); var mail = document.getElementById('txtMail'); alert(mail.value); var sqlmek="update into Student_info set(ID,s_name,l_name,address,pincode,mobile_no,mail_id)values ("; sqlmek = sqlmek + id.value + ",'" + fname.value + "','" + lname.value + "','"; sqlmek = sqlmek + address.value + "'," + pin.value + "," + mob.value + ",'" + mail.value + "')"; alert(sqlmek); var cn = new ActiveXObject("ADODB.Connection"); alert('Hi!'); var strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:/Aptech/dhruv/SMS.mdb"; alert('Hello!'); var rs = new ActiveXObject("ADODB.Recordset"); alert('How are you!!'); cn.Open(strConn); alert('I am Fine!'); rs.Open(sqlmek, cn); alert('Fine'); alert('Press OK to Update your Records Successfully!!.........');}</script></html>

edit.html

Share this post


Link to post
Share on other sites

Hey! thanks for reply but i m just a beginner and i have not learn anything about .asp yet. For this i have a database table .mdb and an html page "studentinfo" and an edit page which is also in html. What ever i edit on my 'edit page' should reflect on the database table it should edit in database automatically. I already have a studentinfo table which uses sql syntex of "insert" and just want to know the correct way for the update syntax of sql. please reply soon....Thanks.

Share this post


Link to post
Share on other sites

If you want to update a database that your site uses that is stored on the server then you need to use ASP, you can't use Javascript for that. Your example will only work in IE and will only update a database on your computer, not the server. This is the section about using ADO to access a database through ASP: http://www.w3schools.com/ado/ado_intro.asp

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...