Jump to content

Problem adding form to Joomla Database using Apostrophe


ashebrian

Recommended Posts

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?

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.