problems with characters < and >

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
hmsg
Forum Commoner
Posts: 42
Joined: Sun May 14, 2006 9:48 am

problems with characters < and >

Post by hmsg »

I getting a field from a mysql DB the field has emails in the format: name <email>.

I don't have any problems inserting the emails in the DB, but when i making a select to the DB i only get the name, because the email that is inside < > isnt shown, i only get the email if i put it in a textarea box!!!

how can i solve this?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

hmsg
Forum Commoner
Posts: 42
Joined: Sun May 14, 2006 9:48 am

Post by hmsg »

that don't resolve if i want to show it in a input form! it only works in a <p> </p> tag. how can i put the value that i receveid form the DB and show it on a input box of a form?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Then please show the relevant piece of your script.
hmsg
Forum Commoner
Posts: 42
Joined: Sun May 14, 2006 9:48 am

Post by hmsg »

html:

<input type="text" name="testers" size="80" maxlength="250" <?php if($testers==null) print(" "); else{ echo "value="; echo htmlentities($testers); }?> />

<!-- In the variable testers i have email in 2 diferent formats: name@domain and name <name@domain>

The problem is withn the second format when i have a email in that format in the input box i only see the name all the other stuff after the first '<' is not being shown

but if i use a text area i have no problem with it -->
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

There are no quotes around the value of the attribute value.
compare to

Code: Select all

<html>
	<head>
		<title>quotes test</title>
	</head>
	<body>
		<form method="post" action="action.php">
			<div>
				<input type="text" name="a" value=abc xyz /> 
				<br />
				<input type="text" name="b" value="abc xyz" />
				<br />
				<input type="text" name="c" value="Jane Doe <janedoe@yaddayad.da" />
				<br />
				<input type="submit" />
			</div>
		</form>
	</body>
</html>
hmsg
Forum Commoner
Posts: 42
Joined: Sun May 14, 2006 9:48 am

Post by hmsg »

And how can i put the quotes around it?
because is in a echo i've already tried \"htmlentities($testers)\" , but it didn't work. what is the alternative way? :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

hmsg wrote:And how can i put the quotes around it?
because is in a echo i've already tried "htmlentities($testers)" , but it didn't work. what is the alternative way? :)

Code: Select all

<input type="text" name="testers" size="80" maxlength="250" <?php if($testers==null) print(" "); else{ echo "value="" .  htmlentities($testers) . """; }?> />
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You know, this has happened before to a other people. The reason the email address doesn't show is because the browser is treating the output of <email@address.tld> as a tag. You are going to have to get the < and > into a < and %gt; before displaying it.
Post Reply