Apostrophes Not Supported on MySql?


#1

Hello I’m new to Dreamhosts,
I have set up a website & MySql here:
http://www.appareltennis.info/

But when I try to login and enter data (edit or add new article) it does not let me enter if the text has an apostrophe. No error is given and I will just be sent back to page as if it was successful .

If I try it with out apostrophes then it will work.

I also ran a duplicate of this site on my last host and never had this happen.

Any help would be good.


#2

The apostrophe needs to be escaped with a backslash depending on whether or not magic quotes is set to on or off. Which is why it works at one host and not another.

Do a Google search for ‘apostrophe mysql’ if you wish to read up about it and addslashes/stripslashes.

You can start at this article…
http://www.webmasterstop.com/63.html


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#3

I added the following like the articles said to the main config file of my site ( I also tried it on index.php):

( "<?php

function myAddSlashes( $string ) {

if (get_magic_quotes_gpc()==1) {

return ( $string );

} else {

return ( addslashes ( $string ) );

}

}

?>" );

but nothing changed and tried to add a sentence with the apostrophe but it didn’t enter again.

I have done something wrong I guess?


#4

I only took a quick glance at that page–but I don’t see where it ever mentions calling the function. Defining a function, by itself, doesn’t do anything.

Where ever you’re inserting the string into the DB, you’ll need to call the function, something like myAddSlashes($your_string_name) before the insert.

So, if you’re working with a POST variable, like “user_name” you could do something like:

$user_name = myAddSlashes($_POST[‘user_name’]);

Then, the string $user_name should be ready to insert.

I’d give that a try.

Or, if your script is already set up to run a certain way, you might want to scroll down on that page to the section about adding a line to your .htaccess file or setting it in the php.ini.


:stuck_out_tongue: Save up to $96 at Dreamhost with 96DOLLARSOFF promo code (I get $1).
Or save $97 with TAKESEILERSCASH.


#5

How many apostrophes will you have to input? If it is just you inputting can you use /’ and just escape each apostrophe until the script is sorted out?


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#6

They should be escaped with a back slash “”, not a forward slash.


Simon Jessey | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#7

Can we meet halfway |’ :slight_smile:

I was waiting to see who would notice my deliberate mistake first. :smiley:


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#8

The Upright Slash: For those embarrassing moments when you’re not sure if a forward or backward slash is appropriate.

:wink:


:stuck_out_tongue: Save up to $96 at Dreamhost with 96DOLLARSOFF promo code (I get $1).
Or save $97 with TAKESEILERSCASH.


#9

I thought I would try changing the httaccess file like this

<?php highlight_string ( " php_flag magic_quotes_gpc on " ); ?>

I changed the Off to On

Nothing happened, I also tried for Php5 as I’m unsure what version is running and still no change so reverted back now.

I’m unsure how I would insert what seiler has said :

$user_name = myAddSlashes($_POST[‘user_name’]);

My config page is nearly 2000 lines and I have no idea where I would use this?


#10

<<<< How many apostrophes will you have to input? If it is just you inputting can you use /’ and just escape each apostrophe until the script is sorted out?>>>>

I would be entering lots of pages of articles with many apostrophes but I also have lots of other sites I wanted to add that will also use apostrophes in lots of articles so as you can see adding a slash each time would be a major PITA.

I’m surprised that others don’t have this problem?


#11

this is still unresolved, any ideas ?


#12

It has cropped up before. I had the same problem with a guestbook script I wrote and had problems with “O’Hara” (not the person, the name.) so I just amended the code where I needed input into the database. That was fairly easy since there were just a few lines.

I used:-

$NameLast = addslashes($_POST[‘NameLast’]);

(So names like O’Hara were stored as O’Hara)

in the input code phase .

Then when reading the database back to screen used:-

echo stripslashes($row[“NameLast”]);

(So records like O’Hara were displayed as O’Hara)

Have you tried switching to PHP4 to see if that helps. You can change back and forth within ‘Manage|Domains>[edit]’. I found I did not have to use add/stripslash under PHP4 because of the default setting of the magic_quotes setting.

I should add of course that the default settings of PHP5 are better. :slight_smile:

Later:
I reread your replies and see you tried the PHP4/5 thing so scrub that…

This is a bit more of the input code to show where I added addsash

$NameLast = addslashes($_POST[‘NameLast’]);
$NameFirst = $_POST[‘NameFirst’];
$Email = $_POST[‘Email’];
$Skills = $_POST[‘Skills’];
$IP = getenv(‘REMOTE_ADDR’);
$dateshow = date(‘dmy His’);

With that huge amount of code you will have to try and strike lucky and find the correct variable that sends input into the database.
Alternatively have a Google for “magic quotes setting htaccess” which might help… or not!


Norm

Opinions are my own views, not DreamHosts’.
I am NOT a DreamHost employee OK!! :@

You act on my advice at your own risk!


#13

Oh please god, don’t use magic quotes. PHP has a nice function that takes care of this.

http://us3.php.net/manual/en/function.mysql-real-escape-string.php

You just call that function on your string before you insert/update.

When you retrieve the data, you don’t need to do anything, it just works.