7 Replies - 1310 Views - Last Post: 13 March 2013 - 11:15 PM

#1 Alfred L  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 09-March 13

Problem check record exists or not in database?

Posted 12 March 2013 - 11:04 PM

Hi guys..how I can check record that already exist in database or not ? I use Microsoft Access here the example :
<%@language="javascript"%>
<html>
<head><title>Signup</title></head>
<script type="text/javascript">

	function validate()
	{
		var id = document.Add.id.value;
		var name = document.Add.name.value;
		var user_group = document.Add.user_group.value;
		var pass = document.Add.pass.value;
		var re_type = document.Add.re_type.value;
		
		if(id=="")
		{
			alert("Please Enter You ID");
			return false;
		}
		if(name=="")
		{
			alert("Please Enter You Name");
			return false;
		}
		if(user_group=="")
		{
			alert("Please Select You Categories");
			return false;
		}
		if(pass=="")
		{
			alert("Please Enter You Password");
			return false;
		}
		if(re_type=="")
		{
			alert("Please Re-Type You Password");
			return false;
		}
		if(pass != re_type)
		{
			alert("Please Check You Password and Confirm Password");
			return false;
		}
	}
</script>
<%
	if(Request.Form("submit")=="Save")
	{
		var DSN = " Provider = Microsoft.JET.OLEDB.4.0; Data Source = C:/Inetpub/wwwroot/demo/Data.mdb";
		var Conn = Server.CreateObject("ADODB.Connection");
		Conn.Open(DSN);
		
		var Id = Request.Form("id");
		var Name = Request.Form("name");
		var User = Request.Form("user_group");
		var User_pass = Request.Form("pass");
		var Re_pass = Request.Form("re_type");
		
				var sqlStmt = "INSERT INTO user_info";
					sqlStmt += "(ID, username, usergroup, userpassword, confirmpassword)";
					sqlStmt += "VALUES";
					sqlStmt += "(";
					sqlStmt += "'" + Id + "',";
					sqlStmt += "'" + Name + "',";
					sqlStmt += "'" + User + "',";
					sqlStmt += "'" + User_pass + "',";
					sqlStmt += "'" + Re_pass + "'";
					sqlStmt += ")";
					
				Conn.Execute(sqlStmt);
			Conn.Close();
			Response.write("You Already Signup"); 
				Response.Redirect("Login.asp");
	}
%>
<body>
	<form name="Add"action="Signup.asp" method="POST"onsubmit="return validate()">
		<table>
			<tr>
				<td>Name<td>:<td><input type="text"name="name">
			</tr>
			<tr>
				<td>ID<td>:<td><input type="text"name="id"maxlength="11">
			</tr>
			<tr>
				<td>User Categories<td>:<td><select name="user_group">
					<option> </option>
					<option value="STUDENT"selected>Student</option>
					<option value="STAFF">Staff</option>
				</select>
			</tr>
			<tr>
				<td>Password<td>:<td><input type="password"name="pass">
			</tr>
			<tr>
				<td> Confirm Password<td>:<td><input type="password"name="re_type">
			</tr>
		</table>
		<input type="submit"name="submit"value="Save"onclick="return confirm('Are you sure want to submit ?');">
	</form>
</body>
</html>


Thanks! :boat:

Is This A Good Question/Topic? 0
  • +

Replies To: Problem check record exists or not in database?

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3510
  • View blog
  • Posts: 10,135
  • Joined: 08-June 10

Re: Problem check record exists or not in database?

Posted 12 March 2013 - 11:31 PM

View PostAlfred L, on 13 March 2013 - 07:04 AM, said:

Hi guys..how I can check record that already exist in database or not ?

it depends on what you want to do with/after that. if you want to avoid duplicate entries, make a unique (or primary) key so that insertion of the duplicate entry simply is not possible.
Was This Post Helpful? 0
  • +
  • -

#3 Alfred L  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 09-March 13

Re: Problem check record exists or not in database?

Posted 13 March 2013 - 06:21 AM

So, if I already set the primary key such as ID because it's unique and how to pop up message like " Record Already Exist" ? if you have any idea could you share ? my purpose is to avoid duplicate record.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3510
  • View blog
  • Posts: 10,135
  • Joined: 08-June 10

Re: Problem check record exists or not in database?

Posted 13 March 2013 - 06:25 AM

you pop up the message when the insertion fails (a duplicate entry on a primary key or unique key always fails).
Was This Post Helpful? 0
  • +
  • -

#5 Alfred L  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 09-March 13

Re: Problem check record exists or not in database?

Posted 13 March 2013 - 09:52 AM

But how to pop up ? could you give some example ? Sorry I am still newbie so need some example.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3510
  • View blog
  • Posts: 10,135
  • Joined: 08-June 10

Re: Problem check record exists or not in database?

Posted 13 March 2013 - 12:20 PM

since I donít know ASP (?) I canít tell you by example how to do that. though basically you just print it out.
Was This Post Helpful? 0
  • +
  • -

#7 Alfred L  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 09-March 13

Re: Problem check record exists or not in database?

Posted 13 March 2013 - 04:47 PM

How about javascript ?
Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3510
  • View blog
  • Posts: 10,135
  • Joined: 08-June 10

Re: Problem check record exists or not in database?

Posted 13 March 2013 - 11:15 PM

Java​Script is not able to handle a database.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1