You are here: Re: mysql_real_escape_string() chopping off after quotes « PHP Programming Language « IT news, forums, messages
Re: mysql_real_escape_string() chopping off after quotes

Posted by Jerry Stuckle on 08/10/07 01:15

Paul Furman wrote:
> mysql_real_escape_string() is apparently chopping off anything that
> follows a quote when I grab the data & put it in a form for editing.
> Sorry if I'm not explaining this properly, I'm pretty confused about
> what's going on but I'm guessing someone recognizes this problem.
>
> I have code like this:
>
> function db_safe($str) {
> $str = addslashes($str);
> return $str;
> }
>
> function html_safe($str) {
> $str = stripslashes($str);
> return $str;
> }
>
> That's on my live server, I'm not sure if magic quotes is on there or I
> forgot to update because my test server version look like:
>
> function db_safe($str) {
> // $str = addslashes($str);
> $str = mysql_real_escape_string($str);
>
>
> Anyways then there's code like this:
>
> if (isset($_REQUEST["submit"])) {
> $latin_name = html_safe($_REQUEST["latin_name"]);
>
>
> if ((isset($_REQUEST["option"])) && ($_REQUEST["option"] ==
> "update")) {
> $id = $_REQUEST["id"];
> $latin_name=db_safe($latin_name);
>
>
> and this is where it's chopping off text after the quote:
>
>
> <form action=.......
> <input type='text' size='57' name='latin_name' value="<?=$latin_name?>">
>
>
>

Check your page source code - you'll probably find it there.

You shouldn't be calling mysql_real_escape_string() on data which is to
be displayed. It should only be called for data you're passing on a
database call.

And if you're going to display it, you should be calling htmlentities as
you display it.

Don't keep the data in your program in either mysql or html encoded
format. Keep the pure string and just massage it as necessary, ie.

<input type='text' size='57' name='latin_name'
value="<?php echo htmlentites($latin_name); ?>">

Also note that I'm not using short tags. Too many hosts have it disabled.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация