|
 |
asp_databases thread: Inserting data into a table
Message #1 by Kat Howlett <kat.howlett@c...> on Thu, 12 Oct 2000 12:51:21 +1000
|
|
Hi
I have written an ASP form that inserts data into an Access table. However
it always inserts a space before and after the data thus messing up my data
retrieval later, I have included my code below. Does anyone know why it does
this? It is driving me mad!
Thanks
Kat
NETWORKFORM.ASP
<% @language = vbscript %>
<%
Option Explicit
Dim company
%>
<!--#include file="adovbs.inc"-->
<%
company = Request.Querystring("company-select")
%>
<html>
<head><title>Network Overview</title></head>
<body>
<% Response.Write "<form action=" &chr(34)
&"networkdata.asp?company-select=" &company &chr(34) &"method=" & chr(34)
&"post" &chr(34) &">" %>
<table width="100%">
<tr>
<td width="40%"><h3>Please enter network information:</h3></td>
<td> </td>
</tr>
<tr>
<td width="40%">Hub/Switch, Brand:</td>
<td><input name="hubbrand"></td>
</tr>
<tr>
<td width="40%">Hub/Switch, Model:</td>
<td><input name="hubmodel"></td>
</tr>
<tr>
<td width="40%">Hub/Switch, Total Ports:</td>
<td><input name="totalports"></td>
</tr>
<tr>
<td width="40%">Hub/Switch, Vacent Ports:</td>
<td><input name="vacentports"></td>
</tr>
<tr>
<td width="40%">Hub/Switch, Speed:</td>
<td><input name="hubspeed"></td>
</tr>
<tr>
<td width="40%">Router Information:</td>
<td><input name="router"></td>
</tr>
<tr>
<td width="40%">IP Configuration:</td>
<td><input name="ipconfig"></td>
</tr>
<tr>
<td width="40%">Email Environment: (describe)</td>
<td><input name="email"></td>
</tr>
<tr>
<td width="40%">Other:</td>
<td><input name="netother"></td>
</tr>
<tr>
<td width="40%"><input type="submit" value="Submit"></td>
<td><input type="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>
NETWORKDATA.ASP
<% @language = vbscript %>
<%
Option Explicit
Dim company
Dim netform
Dim netdata
Dim hubbrand
Dim hubmodel
Dim totalports
Dim vacentports
Dim hubspeed
Dim router
Dim ipconfig
Dim email
Dim netother
%>
<!--#include file="adovbs.inc"-->
<%
company = Request.Querystring ("company-select")
hubbrand=Request.Form ("hubbrand")
hubmodel=Request.Form ("hubmodel")
totalports=Request.Form ("totalports")
vacentports=Request.Form ("vacentports")
hubspeed=Request.Form ("hubspeed")
router=Request.Form ("router")
ipconfig=Request.Form ("ipconfig")
email=Request.Form ("email")
netother=Request.Form ("netother")
set netform = Server.Createobject ("ADODB.connection")
netform.open "CompanyInformation"
netdata = "INSERT INTO NetworkOverview"
netdata = netdata &"(CompanyName,HubBrand,HubModel,"
netdata = netdata &"HubTotalPorts,HubVacentPorts,HubSpeed,"
netdata = netdata
&"RouterInformation,IPConfiguration,EmailEnvironment,"
netdata = netdata &"HardwareOther)"
netdata = netdata & "VALUES"
netdata = netdata & "(' "&company&" ',' "&hubbrand&" ','
"&hubmodel&" ',"
netdata = netdata & "' "&totalports&" ',' "&vacentports&"
',' "&hubspeed&" ',"
netdata = netdata & "' "&router&" ',' "&ipconfig&" ','
"&email&" ',"
netdata = netdata & "' "&netother&" ')"
netform.Execute (netdata)
netform.Close
Set netform = Nothing
%>
<html>
<head><title> </title></head>
<body>
<br><br>
<% Response.Write "<center><a href=company.asp?company-select=" &company
&"><h3>Go Back</h3></a></center>" %>
</body>
</html>
Message #2 by "Ken Schaefer" <ken@a...> on Thu, 12 Oct 2000 22:22:49 +1000
|
|
Because in your code you do this:
> netdata = netdata & "(' "&company&" ',' "&hubbrand&" ','
see there's a space between the ' and the "
Now if you'd done this:
Response.Write(netdata)
it would have been blindingly obvious you were sending extraneous spaces to
the database. Access isn't inserting the space...you are :-)
Also, you should use a function to replace any single quotes there might be
in the form input. They will stuff your SQL statement.
Cheers
Ken
----- Original Message -----
From: "Kat Howlett" <kat.howlett@c...>
To: "ASP Databases" <asp_databases@p...>
Sent: Thursday, October 12, 2000 12:51 PM
Subject: [asp_databases] Inserting data into a table
> Hi
> I have written an ASP form that inserts data into an Access table. However
> it always inserts a space before and after the data thus messing up my
data
> retrieval later, I have included my code below. Does anyone know why it
does
> this? It is driving me mad!
> Thanks
> Kat
>
> NETWORKFORM.ASP
>
> <% @language = vbscript %>
> <%
> Option Explicit
> Dim company
> %>
>
> <!--#include file="adovbs.inc"-->
>
> <%
> company = Request.Querystring("company-select")
> %>
>
> <html>
> <head><title>Network Overview</title></head>
> <body>
> <% Response.Write "<form action=" &chr(34)
> &"networkdata.asp?company-select=" &company &chr(34) &"method=" & chr(34)
> &"post" &chr(34) &">" %>
>
> <table width="100%">
>
> <tr>
> <td width="40%"><h3>Please enter network information:</h3></td>
> <td> </td>
> </tr>
>
> <tr>
> <td width="40%">Hub/Switch, Brand:</td>
> <td><input name="hubbrand"></td>
> </tr>
>
> <tr>
> <td width="40%">Hub/Switch, Model:</td>
> <td><input name="hubmodel"></td>
> </tr>
>
> <tr>
> <td width="40%">Hub/Switch, Total Ports:</td>
> <td><input name="totalports"></td>
> </tr>
>
> <tr>
> <td width="40%">Hub/Switch, Vacent Ports:</td>
> <td><input name="vacentports"></td>
> </tr>
>
> <tr>
> <td width="40%">Hub/Switch, Speed:</td>
> <td><input name="hubspeed"></td>
> </tr>
>
> <tr>
> <td width="40%">Router Information:</td>
> <td><input name="router"></td>
> </tr>
>
> <tr>
> <td width="40%">IP Configuration:</td>
> <td><input name="ipconfig"></td>
> </tr>
>
> <tr>
> <td width="40%">Email Environment: (describe)</td>
> <td><input name="email"></td>
> </tr>
>
> <tr>
> <td width="40%">Other:</td>
> <td><input name="netother"></td>
> </tr>
>
> <tr>
> <td width="40%"><input type="submit" value="Submit"></td>
> <td><input type="reset" value="Reset"></td>
> </tr>
>
> </table>
> </form>
>
>
> ---<BR>
> FREE WEB DEVELOPMENT CODE, CONTENT, AND INSIGHTS<BR>
> IN YOUR INBOX!<BR>
> Get the latest and best HTML, XML, and JavaScript tips, tools, and <BR>
> developments from the experts. Sign up for one or more of EarthWeb?s<BR>
> FREE IT newsletters at http://www.earthweb.com today! <BR>
> ---<BR>
> You are currently subscribed to asp_databases as: ken@a...<BR>
$subst('Email.Unsub')<BR>
>
> </BODY>
> </html>
>
>
> NETWORKDATA.ASP
>
> <% @language = vbscript %>
> <%
> Option Explicit
> Dim company
> Dim netform
> Dim netdata
>
> Dim hubbrand
> Dim hubmodel
> Dim totalports
> Dim vacentports
> Dim hubspeed
> Dim router
> Dim ipconfig
> Dim email
> Dim netother
> %>
>
> <!--#include file="adovbs.inc"-->
>
> <%
> company = Request.Querystring ("company-select")
>
> hubbrand=Request.Form ("hubbrand")
> hubmodel=Request.Form ("hubmodel")
> totalports=Request.Form ("totalports")
> vacentports=Request.Form ("vacentports")
> hubspeed=Request.Form ("hubspeed")
> router=Request.Form ("router")
> ipconfig=Request.Form ("ipconfig")
> email=Request.Form ("email")
> netother=Request.Form ("netother")
>
> set netform = Server.Createobject ("ADODB.connection")
> netform.open "CompanyInformation"
>
> netdata = "INSERT INTO NetworkOverview"
> netdata = netdata &"(CompanyName,HubBrand,HubModel,"
> netdata = netdata &"HubTotalPorts,HubVacentPorts,HubSpeed,"
> netdata = netdata
> &"RouterInformation,IPConfiguration,EmailEnvironment,"
> netdata = netdata &"HardwareOther)"
>
> netdata = netdata & "VALUES"
> netdata = netdata & "(' "&company&" ',' "&hubbrand&" ','
> "&hubmodel&" ',"
> netdata = netdata & "' "&totalports&" ',' "&vacentports&"
> ',' "&hubspeed&" ',"
> netdata = netdata & "' "&router&" ',' "&ipconfig&" ','
> "&email&" ',"
> netdata = netdata & "' "&netother&" ')"
>
> netform.Execute (netdata)
>
> netform.Close
> Set netform = Nothing
> %>
>
> <html>
> <head><title> </title></head>
> <body>
> <br><br>
> <% Response.Write "<center><a href=company.asp?company-select=" &company
> &"><h3>Go Back</h3></a></center>" %>
>
|
|
 |