
March 30th, 2000, 02:39 AM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,575
  
Time spent in forums: < 1 sec
Reputation Power: 24
|
|
|
<i><b>Originally posted by : Chris Snider (csnider@worldnet.att.net)</b></i><br />David,<br /><br />Your problem is in teh following code snippet:<br />...<br />'build the sql statement based on the input from the form<br />strSQL = "INSERT INTO tblSqlAdd(Date, Game, YourName)"<br />strSQL = strSQL & " SELECT "<br />strSQL = strSQL & "'" & request("Date") & "' as text1," <br />strSQL = strSQL & "'" & request("Game") & "' as text2,"<br />strSQL = strSQL & "'" & request("YourName") & "' as text3"<br />...<br /><br />Based on the comment about building the insert from the form input, it should read like this;<br />...'build the sql statement based on the input from the form<br />strSQL = "INSERT INTO tblSqlAdd(Date, Game, YourName)"<br />strSQL = strSQL & " VALUES ("<br />strSQL = strSQL & "'" & request("Date") & "' as text1," <br />strSQL = strSQL & "'" & request("Game") & "' as text2,"<br />strSQL = strSQL & "'" & request("YourName") & "' as text3"<br />strSQL = strSQL & ")"<br /><br />The original version of the SQL statement "INSERT INTO TABLE...SELECT" is telling the database engine to insert into the specified table the values found on an existing table. Switching your statement to the one I provided will take the data from the form and insert as a new record to the specified table.<br /><br />If you need further explanation or comments, please email me.<br /><br />Chris Snider<br /><br />------------<br />David at 3/27/2000 1:46:57 PM<br /><br />I am trying to get this form to insert text into my database, however i keep getting this error:<br />########################################<br />Microsoft OLE DB Provider for ODBC Drivers error '80040e14' <br /><br />[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement. <br /><br />/saber/addsabersql.asp, line 24 <br />########################################<br /><br />I have tried to fix this problem, but have had no luck figuring out what is wrong. Any help would be appreciated, thanks.<br /><br />Dave<br /><br />(my html form and page to insert the data)<br />##############################################<br /><html><br /><br /><head><br /><title>signon</title><br /><br /></head><br /><br /><br /><body><br /><h3 align="center">SQL Add example</h3><br /><br /><br /><br /><td width="424"><form method="post" name="form1" action="addsabersql.asp"><br /> <p><strong>date</strong><br><br /> <input type="text" size="40" name="Date"><br><br /> <strong>Game</strong><br><br /> <input type="text" size="40" name="Game"><br><br /> <strong>Your Name</strong><br><br /> <input type="text" size="40" name="YourName"><br><br /> <p><input type="Submit" value="Submit New Example" name"b1"> </font></p><br /> </form><br /> </td><br /> </tr><br /></table><br /></center></div><br /><br /><p align="center"><!--LINE2--> <br><br /></p><br /><br /><p align="center"><br><br /></p><br /></body><br /></html><br /><br /><br />############################################<br /><br /><br /><%@ Language = "VBScript"%><br /><%<br />'Declare all local variables<br />dim conn<br />dim rs<br />dim strconn<br />dim strsql<br /><br />strsql = ""<br />'set connection string to local variable<br />strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("db/adoandsqladd2.mdb")<br /><br />'build the sql statement based on the input from the form<br />strSQL = "INSERT INTO tblSqlAdd(Date, Game, YourName)"<br />strSQL = strSQL & " SELECT "<br />strSQL = strSQL & "'" & request("Date") & "' as text1," <br />strSQL = strSQL & "'" & request("Game") & "' as text2,"<br />strSQL = strSQL & "'" & request("YourName") & "' as text3"<br /><br />'Set connection object <br />set conn = server.createobject("adodb.connection")<br />conn.open strconn<br />'Use the execute method of the connection object the insert the record<br />conn.execute(strSQL)<br />conn.close<br />set conn = nothing<br />%><br /><html><br /><br /><head><br /><title>SQL Add record example</title><br /></head><br /><br /><body><br /><% = "Your record has been added" %><br /></body><br /></html><br />
|