• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

ASP

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
atent
Asked:
atent
1 Solution
 
hexagon47Commented:
what is the code that you have for the button and what action do you have in the <form>
0
 
Sashi RachabattulaSCRUM Master, .NET Project LeadCommented:
send the code what u did until now
0
 
qudoosCommented:
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.

 
WakieCommented:
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
 
gladxmlCommented:
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
 
gladxmlCommented:
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
 
WakieCommented:
>> 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
 
WakieCommented:
What is the status of this question?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now