Form creating record but not adding data

This is a discussion on "Form creating record but not adding data" within the Databases section. This forum, and the thread "Form creating record but not adding data are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Databases

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 17th, 2007, 21:34
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Form creating record but not adding data

ok i have a form for people to sign up which is this one:

<form method="POST" action="app.asp">
Fields marked (*) are required
<p><font color="#990000"><strong>UserName:*</strong></font><br>
<input type="text" name="UserName" value="UserName">
<p><font color="#990000"><strong>Password:*</strong></font><br>
<input type="text" name="Password" value="Password">
<p><font color="#990000"><strong>Email:*</strong></font> "Must be a Valid Email Address"<br>
<input type="text" name="Email" value="Email">
<p><input type="submit" name="submit" value="Submit">
</form>

and i have a bit of sql that is ment to write that data to a database but it doesnt here is the asp bit

Dim sConnection, objConn , objRS
strusername = UserName
sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=web78-uo; UID=xxxxxxx;PASSWORD=xxxxxxxx OPTION=3"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(sConnection)
Set objRS = objConn.Execute("INSERT INTO accounts (username,password,email ) VALUES(username,password,email)")

for some reason it will not write the data from that form to the database is there somthing wrong with my script if so can any one help me fix it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 18th, 2007, 06:52
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Form creating record but not adding data

What is the error message that you get?
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 18th, 2007, 07:21
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

i dont get an error message thats whats confusing me its just writing blank feilds to the database
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 18th, 2007, 07:42
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Form creating record but not adding data

send me all your .asp page and your database as well in a zipped file.
I'll see what I can do.
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 18th, 2007, 08:12
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

i found the error it was here

Set objRS = objConn.Execute("INSERT INTO accounts (username,password,email ) VALUES(username,password,email)")

changed to

Set objRS = objConn.Execute("INSERT INTO accounts (username,password,email ) VALUES ('" & username & "','" & password & "','" & email & "')")

and works fine but now if the username already exists it still adds it to the database how do i get it so if username already exist's it does a response.write saying that the username already exists in the databse
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 18th, 2007, 08:21
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Form creating record but not adding data

yeah, it was the string ' that you are trying to insert into the database. If it was a number, you will use "
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Oct 18th, 2007, 08:22
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Form creating record but not adding data

Quote:
Originally Posted by Andrew1986 View Post
i found the error it was here

Set objRS = objConn.Execute("INSERT INTO accounts (username,password,email ) VALUES(username,password,email)")

changed to

Set objRS = objConn.Execute("INSERT INTO accounts (username,password,email ) VALUES ('" & username & "','" & password & "','" & email & "')")

and works fine but now if the username already exists it still adds it to the database how do i get it so if username already exist's it does a response.write saying that the username already exists in the databse
You have to add some verification in your add.asp page to handle the error...
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)

Last edited by Monie; Oct 18th, 2007 at 08:25.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 18th, 2007, 08:51
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

i have a bit of verification ill post my add.asp page here

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="includes/functions.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>AlternatePK :: Beta</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>Alternate-PK</h1>
<h2><% Response.Write currentday&" "&datenow&" "&monthnow&" "&year(now)%>
</h2>
</div>
<!-- end div#header -->
<div id="menu">
<ul>
<li><a href="index.asp">Home</a></li>
<li><a href="rules.asp">Rules</a></li>
<li><a href="status.asp">Server Status</a></li>
<li><a href="downloads.asp">Downloads</a></li>
<li><a href="forum.asp">Forum</a></li>
<li><a href="signup.asp">Sign up</a></li>
<li><a href="staff.asp">Staff</a></li>
</ul>
</div>
<!-- end div#menu -->
<div id="page">
<div id="content">
<div id="welcome">
<h1><div style="border-bottom: 1px solid #1C1C1C;">Apply for an account!</div></h1>
<p><%
' declare variables
Dim UserName
Dim Password
Dim Email
' get posted data into variables
UserName = Trim(Request.Form("UserName"))
Password = Trim(Request.Form("Password"))
Email = Trim(Request.Form("Email"))
' validation
Dim validationOK
validationOK=true
If (Trim(UserName)="") Then validationOK=false
If (Trim(Password)="") Then validationOK=false
If (Trim(Email)="") Then validationOK=false
IF (Trim(UserName)="EOF" or Trim(Password)="EOF" or Trim(Email)="EOF") Then validationOK=false & response.write("If you have entered <strong>EOF</strong> in any of the fields then.<br>")
If (validationOK=false) Then
Response.write("Please go back fill in all ")
Response.write("the requied information<br>")
Response.write("<a href=""signup.asp"">Click here</a> to return to the form.")
'does account or email already exist
Dim sConnection, objConn , objRS
sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=xxx; UID=xxx;PASSWORD=xxx; OPTION=3"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(sConnection)
Set objRS = objConn.Execute("SELECT username, email FROM accounts")
IF username = Trim(UserName) then response.write("That username already exist Please go back and try a different usrname")
ELSE
'Add account to Database
sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=xxxxx; UID=xxxxx;PASSWORD=xxxxx; OPTION=3"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(sConnection)
Set objRS = objConn.Execute("INSERT INTO accounts (username,password,email ) VALUES ('" & username & "','" & password & "','" & email & "')")
' redirect to success page
'Response.Redirect("index.asp")
Response.write("<h2>Account Added!</h2>" & "<BR>")
Response.write("Account: " & UserName & "<BR>")
Response.write("Password: " & Password & "<BR>")
Response.write("Email: " & Email)
END IF
%></p>
</div>
</div>
<div id="sidebar">
<ul>
<li id="submenu">
<h2>Navigation</h2>
<ul>
<li><a href="index.asp">Home</a></li>
<li><a href="rules.asp">Rules</a></li>
<li><a href="status.asp">Server Status</a></li>
<li><a href="downloads.asp">Downloads</a></li>
<li><a href="forum.asp">Forum</a></li>
<li><a href="signup.asp">Sign up</a></li>
<li><a href="staff.asp">Staff</a></li>
</ul>
</li>
<li id="submenu">
<h2>Status</h2>
<ul>
<li>Staff:</li>
<li>Players:</li>
<li>Guilds:</li>
</ul>

<li id="submenu">
<h2>Vote For Us</h2>
<ul>
<li></li>
</ul>
</li>
</ul>
</div>
<div style="clear: both; height: 1px"></div>
</div>
<div id="footer">
<p id="legal">Copyright &copy; 2007 Alternate-PK.</p>
<p id="links"><a href="status.asp">Shard Status</a> | <a href="signup.asp">Join Us!</a></p>
</div>
</div>
</body>
</html>

Last edited by Andrew1986; Oct 18th, 2007 at 11:31.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Oct 18th, 2007, 09:15
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,612
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Re: Form creating record but not adding data

Thats a very long page....
I'll have a look at it Andrew.
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Oct 18th, 2007, 09:20
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

Shouldn't you have to query the database first to see if the uersame already exists in the database and then return the error message?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Oct 18th, 2007, 11:33
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

Quote:
Originally Posted by AdRock View Post
Shouldn't you have to query the database first to see if the uersame already exists in the database and then return the error message?
i think you do but i just started to use asp and not quite 100% with it, if some one could help me write the query it would be VERY much appreciated
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Oct 18th, 2007, 13:27
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

I know nothing about asp but here is how i do it in php

PHP: Select all

if( mysql_num_rows(mysql_query("SELECT username FROM users WHERE username = '$username'")) ) {
//error 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Oct 18th, 2007, 13:57
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

ok im currently at work ill be home in a few hours ill try it and ill post the response i get
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Oct 18th, 2007, 17:33
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

nah that didnt work

where should i of put that line in?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Oct 18th, 2007, 17:46
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

Like I said...I know nothing about ASP but it looks like you are nearly all the way there

Code: Select all
Set objRS = objConn.Execute("SELECT username, email FROM accounts")
IF username = Trim(UserName) then response.write("That username already exist Please go back and try a different usrname")
You need to put a WHERE clause in yourt SELECT query so I don't know if this is right or how you insert variables into a sql query but a guess might be

The code is here, it's just hidden...just click select all
Code: Select all
Set objRS = objConn.Execute("SELECT username, email FROM accounts WHERE username=' & username & '")
This is only a guess as I have no idea how to put variables into a sql query
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Oct 18th, 2007, 18:10
Up'n'Coming Member
Join Date: Jul 2007
Location: Barry
Age: 22
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

nope lol still does not want to work lol
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Oct 18th, 2007, 19:16
Highly Reputable Member
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Form creating record but not adding data

You may have more luck posting in the ASP forum.

I have no more ideas

Did you try using a WHERE clause?

You baiscally need to connect to the database, check to see if a record already exists and if it does display the error message. How you perform the query using ASP is beyond me
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #