473,473 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP and MySql

Thank you in advance for helping.

I have a bit of a problem with MySQL and PHP working together. More
specifically when i use htmlspecialchars() to encode my text then load
it into the database, it is interpreting the special characters and
decoding them.

Is there any way that I can perserve this coding and make sure it says
in my database?

Example:

Here is what is entered -- t%20t
Here is what is showing in the database now -- t t
here is what I would like to see -- t%20t

Thank you again,

Nov 17 '06 #1
7 1321
gzerphey wrote:
Thank you in advance for helping.

I have a bit of a problem with MySQL and PHP working together. More
specifically when i use htmlspecialchars() to encode my text then load
it into the database, it is interpreting the special characters and
decoding them.

Is there any way that I can perserve this coding and make sure it says
in my database?

Example:

Here is what is entered -- t%20t
Here is what is showing in the database now -- t t
here is what I would like to see -- t%20t

Thank you again,
htmlspecialchars() is for displaying special characters, not storing
them in the database. You should be using it to display the data, not
place it in the database.

What you should do is store the data as is entered (use
mysql_real_escape_string() to handle any database-specific special
characters).

Then when you pull it out of the database, you can use
htmlspecialchars() before displaying the data.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 17 '06 #2

and why are you storing a url-encoded string?

Nov 17 '06 #3
gzerphey wrote:
I have a bit of a problem with MySQL and PHP working together. More
specifically when i use htmlspecialchars() to encode my text then load
it into the database, it is interpreting the special characters and
decoding them.

Is there any way that I can perserve this coding and make sure it says
in my database?

Example:

Here is what is entered -- t%20t
Here is what is showing in the database now -- t t
here is what I would like to see -- t%20t
What happens when you add this line right at the top of your script,
at line 1?
<?php header('Content-Type: text/plain'); ?>

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Nov 17 '06 #4

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:GJ******************************@comcast.com. ..
gzerphey wrote:
>Thank you in advance for helping.

I have a bit of a problem with MySQL and PHP working together. More
specifically when i use htmlspecialchars() to encode my text then load
it into the database, it is interpreting the special characters and
decoding them.

Is there any way that I can perserve this coding and make sure it says
in my database?

Example:

Here is what is entered -- t%20t
Here is what is showing in the database now -- t t
here is what I would like to see -- t%20t

Thank you again,

htmlspecialchars() is for displaying special characters, not storing them
in the database. You should be using it to display the data, not place it
in the database.

What you should do is store the data as is entered (use
mysql_real_escape_string() to handle any database-specific special
characters).
(Apologies for thread hijacking...)

I took a look at the PHP documentation for mysql_real_escape_string()
(http://uk.php.net/manual/en/function...ape-string.php) and saw
an example of an 'SQL Injection Attack' (Example 2 on that page) along with
their solution (Example 3).

In their example, wouldn't magic quotes be sufficient to thwart the attack?

In their example, someone supplies $_POST['password'] of "' OR ''='". With
magic quotes on, this would become "\' OR \'\'=\'", correct? When used in
their example query, this would be:

SELECT * FROM users WHERE user='username' AND password='\' OR \'\'=\''

Wouldn't that be okay?

I would be grateful if someone could point out any misunderstandings I have.

Thanks.

A.
Nov 19 '06 #5
Andrew C wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:GJ******************************@comcast.com. ..
>>gzerphey wrote:
>>>Thank you in advance for helping.

I have a bit of a problem with MySQL and PHP working together. More
specifically when i use htmlspecialchars() to encode my text then load
it into the database, it is interpreting the special characters and
decoding them.

Is there any way that I can perserve this coding and make sure it says
in my database?

Example:

Here is what is entered -- t%20t
Here is what is showing in the database now -- t t
here is what I would like to see -- t%20t

Thank you again,

htmlspecialchars() is for displaying special characters, not storing them
in the database. You should be using it to display the data, not place it
in the database.

What you should do is store the data as is entered (use
mysql_real_escape_string() to handle any database-specific special
characters).


(Apologies for thread hijacking...)

I took a look at the PHP documentation for mysql_real_escape_string()
(http://uk.php.net/manual/en/function...ape-string.php) and saw
an example of an 'SQL Injection Attack' (Example 2 on that page) along with
their solution (Example 3).

In their example, wouldn't magic quotes be sufficient to thwart the attack?
First of all, magic_quotes is bad. It changes the data without the
user's knowledge. Even worse, it can be turned on or off - either
breaking scripts or requiring extra gyrations to handle either on or off.

Second, mysql_real_escape_string() is a mysql function sensitive to the
charset in use in the table. It is also designed specifically for
inserting into/updating a MySQL database. magic_quotes is a generic
function, not sensitive to character sets.
In their example, someone supplies $_POST['password'] of "' OR ''='". With
magic quotes on, this would become "\' OR \'\'=\'", correct? When used in
their example query, this would be:

SELECT * FROM users WHERE user='username' AND password='\' OR \'\'=\''

Wouldn't that be okay?

I would be grateful if someone could point out any misunderstandings I have.

Thanks.

A.

While magic_quotes *could* be sufficient, it's much better to use the
function designed for the job.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Nov 19 '06 #6
Jerry Stuckle wrote:
Andrew C wrote:
>>
In their example, wouldn't magic quotes be sufficient to thwart the attack?

First of all, magic_quotes is bad. It changes the data without the
user's knowledge. Even worse, it can be turned on or off - either
breaking scripts or requiring extra gyrations to handle either on or off.

Second, mysql_real_escape_string() is a mysql function sensitive to the
charset in use in the table. It is also designed specifically for
inserting into/updating a MySQL database. magic_quotes is a generic
function, not sensitive to character sets.
Third, magic_quotes will be taken away from PHP6.
http://www.corephp.co.uk/archives/19...for-PHP-6.html

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Nov 19 '06 #7

"Pedro Graca" <he****@dodgeit.comwrote in message
news:sl*******************@ID-203069.user.individual.net...
Jerry Stuckle wrote:
>Andrew C wrote:
>>>
In their example, wouldn't magic quotes be sufficient to thwart the
attack?

First of all, magic_quotes is bad. It changes the data without the
user's knowledge. Even worse, it can be turned on or off - either
breaking scripts or requiring extra gyrations to handle either on or off.

Second, mysql_real_escape_string() is a mysql function sensitive to the
charset in use in the table. It is also designed specifically for
inserting into/updating a MySQL database. magic_quotes is a generic
function, not sensitive to character sets.

Third, magic_quotes will be taken away from PHP6.
http://www.corephp.co.uk/archives/19...for-PHP-6.html
Thanks to you both for the points of view and the link.

A.
Nov 20 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mikey | last post by:
Hi all, I'm having great problems trying to install the latest MySQl RPM package onto my Red Hat Linux OS. There is already MySQL v 3.0 pre-installed with the RH Linux distribution disk but I...
0
by: Yun Guan | last post by:
Hello mysql gurus, I am trying to run perl on mysql database on Red Hat box. I want to install DBI and DBD:mysql using CPAN: perl -MCPAN -e shell cpan>install DBI The above succeeded, but...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
2
by: Saqib Ali | last post by:
I installed mySQL and have it running.... but I think I made a mistake somewhere along the line...... I believe I did follow the instructions that were provided with the distribution at:...
1
by: Alex Hunsley | last post by:
I am trying to install the DBD::mysql perl module. However, it claims I need mysql.h: cpan> install DBD::mysql CPAN: Storable loaded ok Going to read /home/alex/.cpan/Metadata Database was...
0
by: ./Rob & | last post by:
Hi gang: I'm experiencing a problem with MySQL -- I updated MySQL from version 4.1.0 to 4.1.10 and now when I login as root it doesn't show all the databases I should have access to, nor it...
2
by: trihanhcie | last post by:
I m currently working on a Unix server with a fedora 3 as an os My current version of mysql is 3.23.58. I'd like to upgrade the version to 5.0.18. After downloading from MYSQL.COM the package on...
1
by: manish deshpande | last post by:
Hi, When i'm installing MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm by the following command: rpm -i MySQL-server-standard-5.0.24a-0.rhel3.i386.rpm the following error is being shown: ...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.