Posting DB Vars

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
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Posting DB Vars

Post by 4Boredom »

Im looking to post a database value into a textbox and its not working.

Code: Select all

<textarea name="a1" id="a1" cols="30" rows="4" value=<?php echo $a1 ?>></textarea>
however.... it works in this

Code: Select all

<input name=username type=text id=username value=<?php echo $a1 ?>>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Posting DB Vars

Post by Luke »

Code: Select all

<textarea name="a1" id="a1" cols="30" rows="4"><?php echo $a1; ?></textarea>
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

thank you
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

Also, you need two other considerations:

Code: Select all

<input name=username type=text id=username value=<?php echo $a1 ?>>

1. Use quotes in the HTML, or you'll have problems

Code: Select all

<input name="username" type="text" id="username" value="<?php echo $a1 ?>">
2. Escape variables before outputting them to HTML or you'll have problems

Code: Select all

<input name="username" type="text" id="username" value="<?php echo htmlentities($a1, ENT_QUOTES, "utf-8") ?>">
(adjust the params to your system, but don't omit them, or you'll ... you guessed right: have problems :) )
Post Reply