ashebrian Posted March 7, 2010 Share Posted March 7, 2010 Hi, I have a problem with adding information to a database using both mysql and Joomla. I know people don't normally bother with this but I want to know how to add an apostrophe to a field name that will allow this to be added to the mysql database. Making a code like this, will prob have to be added to the database.php file as it is where the insert statements are. I may be wrong.....just want to be corrected. It may also have to be where all the insert statements are outside of the database.php file too. Does anyone have info on this that will help me? There is a javascript like: var lsLastName = "O'Brien"; var lsRegExp = /'/g; lsLastName = String(lsLastName).replace(lsRegExp, "''") However this has the string O'Brien already written in it but it's not what i want. I would like it to be without it so the user can input it themselves. Maybe using the function: function quoteReplace(psString) { var lsRegExp = /'/g; return String(psString).replace(lsRegExp, "''"); } Is this Javascript as well or php? i think its javascript. So what else will need to be added and where if i use the function above? Is there a way this can be done in Php?? By using the mysql_real_escape_string: <?php $user_name = mysql_real_escape_string ($_POST['user_name']); $user_name = str_replace("'", "\'", $user_name); ?> Whats the disadvantages of using mysql_real_escape_string, and where shall i put the stripslashes($user_name) when i display it back on a page or it will have the "\"? as shown in line 2 above. Finally, another way i heard of is changing all they mysql insert statements to something like: $sql = "INSERT INTO mytable SET comments = '".mysql_real_escape_string($user_name)."'"; Any advice please? Quote Link to comment Share on other sites More sharing options...
karpagam Posted March 18, 2010 Share Posted March 18, 2010 Hi... Can you use this code below, <?php $user=stripslashes($_POST['user_name']); $user_name = str_replace("'", "", $user); ?> Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.