Page 1 of 1

double quotes in varchar

Posted: Thu Jul 28, 2005 3:41 am
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?

Posted: Thu Jul 28, 2005 5:02 am
by shiznatix
addslashes(); then stripslashes();

Posted: Thu Jul 28, 2005 6:29 am
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?

Posted: Thu Jul 28, 2005 9:16 am
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.

Posted: Thu Jul 28, 2005 9:22 am
by timvw
You should check if the magic_quotes stuff is messing with your data..

When inserting you should use mysql_real_escape_string..