double quotes in varchar

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

double quotes in varchar

Post by gurjit »

Hi,

I have a set of data transferred from a csv to a db table.

The data goes into the varchar field fine when converted but when i manipulate the data to store it into a relational table using php i get any string which is like:

" hello

a double quote without end double quotes stored as

"
hello

in a varchar field in mysql, which is strange

when i insert into a db table i use the following to store the data to a string:

<?php
$stu_alt_tel = mysql_escape_string($EMERGENCY);
?>

any ideas how i can put any string no matter what format on one line and escape any kinds of problems?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

addslashes(); then stripslashes();
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

i have tested this, it goes in database ok

BUT

the problem is when i out put it in a

Code: Select all

<input type="text" name="field1" value="<?php echo stripslashes($get_stuP['stu_alt_tel']);?>">
with $get_stuP['stu_alt_tel'] equal to "fddfgfdg

with the speech mark and no end speech mark it does not get displayed?
choppsta
Forum Contributor
Posts: 114
Joined: Thu Jul 03, 2003 11:11 am

Post by choppsta »

When you output anything to an HTML page (that you don't want to be treated as HTML), you should use:

Code: Select all

htmlspecialchars($var);
This changes double quotes (") into &amp;quot; and so won't break the input tag by closing it early.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

You should check if the magic_quotes stuff is messing with your data..

When inserting you should use mysql_real_escape_string..
Post Reply