Author Topic: Problem adding form to Joomla Database using Apostrophe  (Read 758 times)

0 Members and 1 Guest are viewing this topic.

Offline ashebrianTopic starter

  • Irregular
  • Posts: 1
    • View Profile
Problem adding form to Joomla Database using Apostrophe
« on: March 07, 2010, 05:20:17 PM »
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:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
$sql = "INSERT INTO mytable SET comments = '".mysql_real_escape_string($user_name)."'";
Any advice please?

Offline karpagam

  • Irregular
  • Posts: 13
    • View Profile
Re: Problem adding form to Joomla Database using Apostrophe
« Reply #1 on: March 18, 2010, 08:19:23 AM »
Hi...

       Can you use this code below,
<?php
        $user=stripslashes($_POST['user_name']);
        $user_name = str_replace("'", "", $user);
?>
Thanks