PHP/Mysql/special characters problem

This is a discussion on PHP/Mysql/special characters problem within the PHP Language forums, part of the PHP Programming Forums category; "Mosher" <mosh_king2000@yahoo.com> wrote in news:9NqdnaqolKxu6mSi4p2dnA@comcast.com: > Hi Ken, > > Thanks ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 01-05-2004
Ken Robinson
 
Posts: n/a
Default Re: PHP/Mysql/special characters problem

"Mosher" <mosh_king2000@yahoo.com> wrote in
news:9NqdnaqolKxu6mSi4p2dnA@comcast.com:

> Hi Ken,
>
> Thanks for this, but it did not work. Once again (prior to your code),
> the data gets written to the db just fine, quotes and all. But when I
> call it back up to edit it, that is where the problem is. First, the
> field data:
>
> O'Leary "special"
>
> ...only displayed O'Leary when called back up. I then was able to get
> around that by the following line of code:
>
> <input type=text name=description value="<? echo
> htmlentities($row[description])?>">
>
> This did display the full data above with quotes, etc. But when I look
> in the actual source code of the webpage being displayed, it shows:
>
> O'Leary&quot;special&quot;
>
> ...in the field and when I try to write to db, it only writes:
>


I've had similar problems. It's in the DB with the quotes and I used to
run around in circles trying to get it back in after displaying it on a
form and getting the value back. That's why I've started to store the
urlencoded format in the database.

So you would do:
<input type=text name=description value="<? echo urldecode($row
[description])?>">
in your form.

In your database update command use something like: "update .... set
description='".urlencode(stripslashes($_POST['description']))."'..."

You might have to write a one-time job to update all the text fields in
your database to conform to the new method or you can just implement it
and each field will be updated as time goes on.

Ken
Reply With Quote
  #12 (permalink)  
Old 01-05-2004
steven mestdagh
 
Posts: n/a
Default Re: PHP/Mysql/special characters problem

> This did display the full data above with quotes, etc. But when I look in
> the actual source code of the webpage being displayed, it shows:
>
> O'Leary&quot;special&quot;
>
> ...in the field and when I try to write to db, it only writes:
>
> O'Leary
>
> Any other ideas?


after form submission, i use
$_POST['var'] = mysql_escape_string(stripslashes($_POST['var']));
before submitting $_POST['var'] to my database.

maybe you can also echo $_POST['var'] after you submit the form to check
what is in it.

if you use the GET method, the &quot; entity may cause problems as all
variables are transmitted like
http://php.net/script.php?var1=foo&v...;problem&quot;
if this is the case, maybe just try the POST method instead?

good luck
steven.
Reply With Quote
  #13 (permalink)  
Old 01-07-2004
Mosher
 
Posts: n/a
Default Re: PHP/Mysql/special characters problem

Ken - the whole thing works now! But the problem was caused by another
issue. I believe that there was another query writing the data to db (so it
was getting written twice) and due to this, there was the problem - one
query was correct and the other wasn't. I removed the latter query and now
it is working. It had me totally stumped because this hasn't been too much
of an issue for me before.

Anyway, thanks much for the advice. Perhaps I'll try your ideas next time.

Later,

Mosher

"Ken Robinson" <sendspamhere@rbnsn.com> wrote in message
news:70499a4b13da5b8d11ff30ca436b1de6@news.teranew s.com...
> "Mosher" <mosh_king2000@yahoo.com> wrote in
> news:9NqdnaqolKxu6mSi4p2dnA@comcast.com:
>
> > Hi Ken,
> >
> > Thanks for this, but it did not work. Once again (prior to your code),
> > the data gets written to the db just fine, quotes and all. But when I
> > call it back up to edit it, that is where the problem is. First, the
> > field data:
> >
> > O'Leary "special"
> >
> > ...only displayed O'Leary when called back up. I then was able to get
> > around that by the following line of code:
> >
> > <input type=text name=description value="<? echo
> > htmlentities($row[description])?>">
> >
> > This did display the full data above with quotes, etc. But when I look
> > in the actual source code of the webpage being displayed, it shows:
> >
> > O'Leary&quot;special&quot;
> >
> > ...in the field and when I try to write to db, it only writes:
> >

>
> I've had similar problems. It's in the DB with the quotes and I used to
> run around in circles trying to get it back in after displaying it on a
> form and getting the value back. That's why I've started to store the
> urlencoded format in the database.
>
> So you would do:
> <input type=text name=description value="<? echo urldecode($row
> [description])?>">
> in your form.
>
> In your database update command use something like: "update .... set
> description='".urlencode(stripslashes($_POST['description']))."'..."
>
> You might have to write a one-time job to update all the text fields in
> your database to conform to the new method or you can just implement it
> and each field will be updated as time goes on.
>
> Ken



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:51 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0