473,385 Members | 1,766 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,385 software developers and data experts.

How do I escape form input values, C style?

Hey Folks,

How do I go about escaping values entered into a form so they can be
dumped into a database?

For the record, I have no idea how the functions I'm using to write to the
database work because it's a proprietary product that I have to use, and
"they" don't release any documentation about how their internals work. I
just need to be able to prepare the string before it's passed to their
function.

For example, the classic last name = O'Maley... and I can't use escape(),
I need it to come out O\'Maley.

A single quote isn't the only thing I'm concerned with but it's a start,
and solves my immediate problem.

Is there an all powerful function that escapes all special
(non-alphanumeric) characters or do I need some fancy regex?

Any help is, as always, appreciated.

--
Life is short, but wide. -KV

Jul 23 '05 #1
3 2006
Ivan Marsh wrote:
Hey Folks,

How do I go about escaping values entered into a form so they can be
dumped into a database?


Values entered into forms are 'escaped' automatically by the browser
before submission to the server. O'Malley will appear in the URI sent
to the server as:

O%27Malley

Of course, if you are talking about un-escaping at the server, that
has nothing to do with client-side JavaScript.

[...]
--
Fred
Jul 23 '05 #2
On Thu, 14 Apr 2005 01:24:37 +1000, Fred Oz wrote:
Ivan Marsh wrote:
Hey Folks,

How do I go about escaping values entered into a form so they can be
dumped into a database?


Values entered into forms are 'escaped' automatically by the browser
before submission to the server. O'Malley will appear in the URI sent
to the server as:

O%27Malley

Of course, if you are talking about un-escaping at the server, that
has nothing to do with client-side JavaScript.


I guess I should include an example... this data is being grabbed and
written run-time, and I don't think a "true" form submission is being
performed.

Here's some pseudo-code:

<script type="text/javascript">

query_string = "UPDATE mytable SET myfield = '" +
ProprietaryFieldGrab("Last_Name") + "' WHERE otherfield = '" +
ProprietaryFieldGrab("Phonenum") + "';";

ProprietaryDatabaseWrite(query_string, databasename);

</script>

Last_Name and Phonenum are fields in the form.

I need to do a C-like escape in query_string whenever
ProprietaryFieldGrab() is called.

Oh... and the proprietary functions are not in my control or editable by
me.

Any takers?

--
Life is short, but wide. -KV

Jul 23 '05 #3
fox


Ivan Marsh wrote:
On Thu, 14 Apr 2005 01:24:37 +1000, Fred Oz wrote:

Ivan Marsh wrote:
Hey Folks,

How do I go about escaping values entered into a form so they can be
dumped into a database?


Values entered into forms are 'escaped' automatically by the browser
before submission to the server. O'Malley will appear in the URI sent
to the server as:

O%27Malley

Of course, if you are talking about un-escaping at the server, that
has nothing to do with client-side JavaScript.

I guess I should include an example... this data is being grabbed and
written run-time, and I don't think a "true" form submission is being
performed.

Here's some pseudo-code:

<script type="text/javascript">

query_string = "UPDATE mytable SET myfield = '" +
ProprietaryFieldGrab("Last_Name") + "' WHERE otherfield = '" +
ProprietaryFieldGrab("Phonenum") + "';";

ProprietaryDatabaseWrite(query_string, databasename);

</script>

Last_Name and Phonenum are fields in the form.

I need to do a C-like escape in query_string whenever
ProprietaryFieldGrab() is called.

Oh... and the proprietary functions are not in my control or editable by
me.

Any takers?


query.replace(/([\'\"])/g,"\\$1"); ?
Jul 23 '05 #4

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

Similar topics

2
by: Sam Goffin | last post by:
Hi how can I resize my form borders in .NET (either VB or C#)? In one of my programs I want to extend the usual form size at one end (when the user clicks the "Details..." button), so I need...
2
by: Jack | last post by:
Hi, I got a simple form where one needs to input data. The data is being processed in an asp page. However, I cannot figure out why couple of values I am typing in the form is not being retrived...
15
by: soup_or_power | last post by:
Hello All: I'm having a whale of a problem with the following code. When the words beginning with sugg contain an escaped single-quote (\' ==> back-slash followed by quote) the script causes an...
6
by: Walter L. Preuninger II | last post by:
I need to convert escape sequences entered into my program to the actual code. For example, \r becomes 0x0d I have looked over the FAQ, and searched the web, with no results. Is there a...
4
SHOverine
by: SHOverine | last post by:
I have a 3-part form that I am having trouble with. First part is to select the user group and the week and year that I want to submit results for, this calls the elements that I want to update. ...
1
by: Muchach | last post by:
Hello, Ok so what I've got going on is a form that is populated by pulling info from database then using php do{} to create elements in form. I have a text box in each table row for the user to...
2
by: sammiesue | last post by:
Hi, I have form with 2 autosummed textboxes ("total" and "casinototal"). I would like to have a grand total textbox ("grandtotal") get its value from summing "total" and "casinototal", but it...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
8
by: ahilar12 | last post by:
Hi experts, I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.