PDA

Click to See Complete Forum and Search --> : storing strings with spaces using asp


Nov 16th, 2000, 11:01 AM
i have a database table field that holds a person's full name and when i use asp to insert data into that field it only copies the string before the space. like if i enter 'john percival,' it only inserts john into the table field.

sorry, but i'm new to asp so i still don't really know my way around it to well.

Skeen
Nov 17th, 2000, 03:08 AM
Post a code segment.

If you're using vb script in asp's, I presume you'll be using input text boxes, so what I do is use two/ three pages whereby the first has the input text boxes where you would type 'john percival'. Use an HTML from and post it to point to your next script. Her place the input to the text box into a variable:

Say the text box is called 'txt1' the VBScript to retrieve what has been typed in is:

NameVariable = Request.Form("T1")

Then insert the variable into your SQL statement:

SQL = "INSERT INTO tablename (fieldname) " _
& "VALUES ( '" & NameVarible & "') "

This will insert what ever is in the string variable 'NameVariable', even white space. Heres a quick bit of code below for a couple of test pages:

PAGE1 - save as - "Name_Input.html" -

<html>
<head><title>Name Input</title>
</head>
<body>
<form method="post" action="input.asp">
<input type="text" name="T1">
<input type="submit" name="Submit1" value="Submit">
<input type="reset" name="reset1" value="Reset">
</form>
</body>
</html>

PAGE2 - save as - "input.asp" (This is a hidden script)

<%

Dim Name
Dim cnOBJECT
Dim rsInData

Set cnOBJECT= CreateObject ( "ADODB.Connection" )
cnOBJECT.ConnectionString = " Provider=MSDASQL; " _
& " DSN=DatabaseName;" _
& " UID=Username; " _
& " PWD=Password;"
cnOBJECT.open
Name = Request.Form("T1")

SQL = "INSERT INTO tablename (fieldname) " _
& "VALUES ( '" & NameVarible & "') "

Set rsInData = cnOBJECT.Execute(SQL)

Response.Redirect "Data_Logged.html"
cnOBJECT.Close
Set rsInData = Nothing

%>

PAGE3 - save as "Data_Logged.html" -

<html>
<head><title>Data Logged</title>
</head>
<body>
<center><h1>Data has been logged into the database.</h1></center>
<form method="post" action="input.asp">
<input type="submit" name="Submit2" value="Continue">
</from>
</body>
</html>

This will appear as only two pages, the title where you input a name, this calls the second page which inputs the text you placed in the text box but does not return anything to the screen. After inputing to the database it uses the response redirect to take you to a confirmation page where on the click of the button it takes you back to the first page. This is all a web based/browser front end, but thats ASP's for ya. To test locally I use Personal Web Server from microsoft, its sets up a root directory and that where you place your scripts, just type the name of your PC into the browser and you can view your ASP's.
ie "http://pcnamehere.
You can get it for Win98/WinNT but I don't know about Win2K or ME. But its a free download from microsoft.

Hope this helps, I've got hooked on VBscript in asp's 'cos it is real quick and well easy, especially for database web front ends.

Cheers 'n' Beers

Skeen

Nov 17th, 2000, 09:54 AM
thanks!