473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sinlge quotes replace problem

Hi group I'm having trouble using the replace command
Here's my code below

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/conn.asp" -->

<%
if( String(Request.Form("ProductName")) != "undefined" ){//formfield
is not empty
var NavID = 1;

var ProductName = String(Request.Form("ProductName"));
var Price = String(Request.Form("Price"));
var Descript = String(Request.Form("Description"));
var ProductCode = String(Request.Form("ProductCode"));
//get the form fields and put into vars
var TableFields = "ProductName,Price,Description,NavID,ProductCo de";

var FormFields = "'" + ProductName + "','" + Price + "','" + Descript
+ "','" + NavID + "','" + ProductCode+"'" ;

/// it works ok if i remove the replace
FormFields=FormFields.replace("'", "''");
conn = Server.CreateObject('ADODB.Command');

conn.ActiveConnection = conn_STRING;

conn.CommandText = ("insert into products ("+ TableFields +") values
('" + FormFields + ")" );
conn.Execute();
conn.ActiveConnection.Close();

}

%>

any suggestions?
Jul 19 '05 #1
3 1643

"Roy Adams" <ro*******@ntlworld.com> wrote in message
news:13**************************@posting.google.c om...
Hi group I'm having trouble using the replace command
Here's my code below

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/conn.asp" -->

<%
if( String(Request.Form("ProductName")) != "undefined" ){//formfield
is not empty
var NavID = 1;

var ProductName = String(Request.Form("ProductName"));
var Price = String(Request.Form("Price"));
var Descript = String(Request.Form("Description"));
var ProductCode = String(Request.Form("ProductCode"));
//get the form fields and put into vars
var TableFields = "ProductName,Price,Description,NavID,ProductCo de";

var FormFields = "'" + ProductName + "','" + Price + "','" + Descript
+ "','" + NavID + "','" + ProductCode+"'" ;

/// it works ok if i remove the replace
FormFields=FormFields.replace("'", "''");
try

FormFields=replace(FormFields,"'", "''");


conn = Server.CreateObject('ADODB.Command');

conn.ActiveConnection = conn_STRING;

conn.CommandText = ("insert into products ("+ TableFields +") values
('" + FormFields + ")" );
conn.Execute();
conn.ActiveConnection.Close();

}

%>

any suggestions?

Jul 19 '05 #2
This...
conn.CommandText = ("insert into products ("+ TableFields +") values
('" + FormFields + ")" );

Looks like it has an apostrophe right after the opening bracket.
You've replaced all of your form field delimiters with double apostrophes.
So your statement is going to look like.....
insert into products (ProductName,Price,Description,NavID,ProductCode)
values
(''productname'',''price'',''description'',''navid '',''productcode'')

I believe what you want to do is.....

Price.replace("'","''")
ProductName.Replace("'","''")
//ETC..

var FormFields = "'" + ProductName + "','" + Price + "','" + Descript
+ "','" + NavID + "','" + ProductCode+"'" ;

So that your result will look like
insert into products (ProductName,Price,Description,NavID,ProductCode)
values
('product''sname',price,'description',navid,'produ ctcode')

Note the double apostrophe after the t in productsname. This will insert
product'sname into the ProductName field.
You'll also note that price has no apostrophes as I'm assuming that's a
number field.

"Roy Adams" <ro*******@ntlworld.com> wrote in message
news:13**************************@posting.google.c om...
Hi group I'm having trouble using the replace command
Here's my code below

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/conn.asp" -->

<%
if( String(Request.Form("ProductName")) != "undefined" ){//formfield
is not empty
var NavID = 1;

var ProductName = String(Request.Form("ProductName"));
var Price = String(Request.Form("Price"));
var Descript = String(Request.Form("Description"));
var ProductCode = String(Request.Form("ProductCode"));
//get the form fields and put into vars
var TableFields = "ProductName,Price,Description,NavID,ProductCo de";

var FormFields = "'" + ProductName + "','" + Price + "','" + Descript
+ "','" + NavID + "','" + ProductCode+"'" ;

/// it works ok if i remove the replace
FormFields=FormFields.replace("'", "''");
conn = Server.CreateObject('ADODB.Command');

conn.ActiveConnection = conn_STRING;

conn.CommandText = ("insert into products ("+ TableFields +") values
('" + FormFields + ")" );
conn.Execute();
conn.ActiveConnection.Close();

}

%>

any suggestions?

Jul 19 '05 #3
Roy
Hi TomB
thanks for your help, you were exactly right,
but after i did that i found that it worked for the first single quote
but found now if a user inputs more than one single or double quote into
the text field it threw up errors again so i tried
ProductName=ProductName.replace(/'/g, "''");
which worked!!
cheers

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jason | last post by:
I have several tables with quite a few fields and I'm getting errors when trying to insert records with single quotes in the data like: name = John O'Henry or a city name of O'Fallen So I went...
24
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double...
6
by: G. | last post by:
This is an obvious bug in the String.Replace function: //load a XML string into a document XmlDocument doc = new XmlDocument(); doc.LoadXml("<test id='' />"); //Obtain the string...
7
by: gar | last post by:
Hi, I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code text= Replace(text, """", "'" This works fine (for normal double quotes).The problem...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
4
by: Justin Fancy | last post by:
Hi everyone, I need to replace all instances of a double quote(") with two single quotes('') in a text file. I already have some replacements of strings going on, but I tried this one, but the...
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello, I have some XML that is returned to my application from another vendor that I cannot change before it gets to me. I can only alter it after it gets to my application. That being said, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.