Page 1 of 1
how to get test boxes filled in on load
Posted: Sun Feb 01, 2004 10:54 am
by Deemo
once again, i come to you guys for help, and i hope u can help again
i have a section in my site where people login to edit their own personal profiles. however, i do not know how to make it so that when that page loads, it automatically reads the database, and fills in the specific columns into form elements.
for example, if their is a shout-out box, i want the editprofile.php to load up and whatever the user saved under te shout-out box will load up with the page inside the testbox
my explanation isnt too good, but you prolly get the idea by now. how do i do it?
Posted: Sun Feb 01, 2004 1:09 pm
by vigge89
you want to load previous saved stuff nto your textbox?
not hard at all, just tell me if i got it right

Posted: Sun Feb 01, 2004 1:17 pm
by Deemo
yeah, thats exactly what i wanna do
i suck at explaining lol
Posted: Sun Feb 01, 2004 1:33 pm
by vigge89
do you know how to load data from the database?
if you do, just use this:
Code: Select all
<?php
$string = "this is what the textbox should contain";
echo "
<textarea name='textbox' cols='30' rows='6'>$string</textarea>
";
?>
Posted: Sun Feb 01, 2004 1:43 pm
by Deemo
oh ok, thanks a bunch
Posted: Sun Feb 01, 2004 4:08 pm
by DuFF
You can also do:
Code: Select all
<?php
$username = "Info From DB";
echo "<input type="text" name="username" value="$username">";
?>
Posted: Sun Feb 01, 2004 9:18 pm
by Deemo
well, i got that all fixed, but now i have a new problem. When people write something, like their favorite quesote for example, in a multiline textbox, it is written to the database as one big strand with no endlines. for example if i wanted to write this:
"My nipples explode with delight!"
-John Cleese
it would show up as this
"My nipples explode with delight!" -John Cleese
how do i make it so it is written to the database like how it was written?
Posted: Mon Feb 02, 2004 12:50 am
by vigge89
does it get outputted when you return it from the database (ie normal text)?
then just use nl2br($string) to make all the newlines saved in the database change to <br />'s
Posted: Mon Feb 02, 2004 5:42 pm
by Deemo
ok, that fixed that problem, and the profile thing is done. thank you very much
now i have another problem that is unrelated to this toppic, but i didnt want to spam your forums. so here it is: is there a random letter generator in php? for example, i want to create passwords that are completely random. how will i go through doing that.?
also..is there a reverse nl2br function that takes away the <br /> when the string is loaded later?
Posted: Mon Feb 02, 2004 8:15 pm
by Unipus
Code: Select all
function generatePassword ($length =
// from Jon Haworth
{
// start with a blank password
$password = "";
// define possible characters
$possible = "0123456789bcdfghjkmnpqrstvwxyz";
// set up a counter
$i = 0;
// add random characters to $password until $length is reached
while ($i < $length) {
// pick a random character from the possible ones
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
// we don't want this character if it's already in the password
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
// done!
return $password;
}
As for the second question, str_replace() will do that, don't know if there's an easier way.