text box question (Full Version)

All Forums >> [Web Development] >> General Web Development



Message


anand -> text box question (5/24/2008 10:27:23)

Hi everyone,

I have a few text box's on my site and i would like to know how can i replace if a user enters a single quote ' and re-place it with nothing...

The problem i'm having is when a user enters a single quote i get an error on the page because this info gets inputed into a database...

Hope someone can help me...

[removed]




Mane -> RE: text box question (5/24/2008 17:49:58)

What language are you using? PHP? ASP?
It's better to read up on the language first before using it in a website, in order to create safe and secure pages.

To escape quotes in PHP use the addslashes() function:
$var = addslashes($var);

However members of this forum would certainly stress that it's important to learn the language first.

Mike54: You seem to have removed something from the post - If this was actually some intricate form of spam I'm sorry for responding.




sarge -> RE: text box question (5/26/2008 21:16:20)

I use <% mytext = Replace(mytext, "'", "''") %>

That way the user's quote is preserved.




mtfm -> RE: text box question (5/27/2008 17:28:22)

There's also a Javascript method available, too.

I also substituted for the quote, but I put a - in place of it, because a single quote caused problems with the javascript. You could also replace it with nothing, just be removing the - from the code. Here's my code.

var variable_name = new_variable_name.replace (/"/g,'-');


You're basically taking your variable you should have already declared, manipulating it to remove the ' and declaring a new variable. Then when it comes time to insert the form result into your database, make sure that code calls the new variable name, and you're done.

On a side note, if you are doing much in javascript look into what's called "regular expressions." This is an example of one, and it is much, much easier than explicitly stating the if/then paramaters.





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875