?
Solved

ASP

Posted on 2003-03-31
8
Medium Priority
?
199 Views
Last Modified: 2010-04-06
In tag form i declare a button "AddNew" which react at post command. This button add in a database one record when the user push the button addnew. When user make refresh at the IE in database add a new record identical with before record. Where is the prblem? How can i change the value of AddNew button.
0
Comment
Question by:atent
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:hexagon47
ID: 8237901
what is the code that you have for the button and what action do you have in the <form>
0
 
LVL 4

Expert Comment

by:Sashi Rachabattula
ID: 8237951
send the code what u did until now
0
 
LVL 1

Expert Comment

by:qudoos
ID: 8240959
what i have understood from the question is that the record gets added to the database when the Add new button is pressed. and if the user refreshes the page it gets added again. Well i would advice that before adding you should check if that record already exists or not. if it does then dont add it and come up with a message saying that this has already been added. so the user has to fill the form again.
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Accepted Solution

by:
Wakie earned 500 total points
ID: 8249095
Hi atent,

Assuming this is your form:

<html>
<body>
<form method="post">
Username: <input type="text" name="username"><br>
Password: <input type="text" name="password"><br>
<input type="submit" value="Add New">
</form>
</body>
</html>

Use the following ASP code to add the record if the record doesn't already exist:

<%
'Fetch submitted data
Username = Request.Form("Username")
Password = Request.Form("Password")

'Create and open database connection
Set DB = Server.CreateObject("ADODB.Connection")
'ConnectionString = **Your connection string here**
DB.Open ConnectionString

'Check for existing record
SQL = "SELECT * FROM Members WHERE Username = '" & Username & "'"
Set RS = DB.Execute(SQL)
If RS.EOF Then
'  Member does not exist, add record
   SQL = "INSERT INTO Members (Username, Password) VALUES ('" & Username & "', '" & Password & "')"
   DB.Execute(SQL)
Else
'  Member exists, give an error instead of adding record
   Response.Write "The username <b>" & RS("Username") & "</b> already exists in the database. Please choose another username."
End If
%>

Regards,
Wakie.
0
 
LVL 15

Expert Comment

by:gladxml
ID: 8250498
atent,

The simplest solution is that

assuming that your page is being passed to itself then  

after the addnew process try to use

response.redirect "yourpagename.asp"

or if it is being passed on other page... try to redirect o other pages..

response.redirect "other.page"

HTH...

HAppy programming...

0
 
LVL 15

Expert Comment

by:gladxml
ID: 8250745
atent,

you can try this...

response.redirect Request.ServerVariables("SCRIPT_NAME")


Or another solution

is to check if the record alredy exist but instead of an error message if data exist,  you can make use of the update statement... to avoid data duplication...

HTH...

HAppy programming...
0
 
LVL 4

Expert Comment

by:Wakie
ID: 8251188
>> is to check if the record alredy exist but instead of an error message if data exist,  you can make use of the update statement... to avoid data duplication... <<

I beat you to that one :-)

Regards,
Wakie.
0
 
LVL 4

Expert Comment

by:Wakie
ID: 8281831
What is the status of this question?
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
The viewer will learn how to count occurrences of each item in an array.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question