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.
|
|
|
|
|
![]() |
||
Form creating record but not adding data
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
#1
|
|||
|
|||
|
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 |
|
|
|
#2
|
|||
|
|||
|
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)
|
|
#3
|
|||
|
|||
|
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
|
|
#4
|
|||
|
|||
|
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)
|
|
#5
|
|||
|
|||
|
Re: Form creating record but not adding data
i found the error
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 |
|
#6
|
|||
|
|||
|
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)
|
|
#7
|
|||
|
|||
|
Re: Form creating record but not adding data
Quote:
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)
Last edited by Monie; Oct 18th, 2007 at 08:25. |
|
#8
|
|||
|
|||
|
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 © 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. |
|
#9
|
|||
|
|||
|
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)
|
|
#10
|
|||
|
|||
|
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?
|
|
#11
|
|||
|
|||
|
Re: Form creating record but not adding data
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
|
|
#12
|
|||
|
|||
|
Re: Form creating record but not adding data
I know nothing about asp but here is how i do it in php
|
|
#13
|
|||
|
|||
|
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
|
|
#14
|
|||
|
|||
|
Re: Form creating record but not adding data
nah that didnt work
where should i of put that line in? |
|
#15
|
|||
|
|||
|
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
The code is here, it's just hidden...just click select all
|
|
#16
|
|||
|
|||
|
Re: Form creating record but not adding data
nope lol still does not want to work lol
|
|
#17
|
|||
|
|||
|
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 |