how to get test boxes filled in on load

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
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

how to get test boxes filled in on load

Post 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?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

you want to load previous saved stuff nto your textbox?
not hard at all, just tell me if i got it right :wink:
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

yeah, thats exactly what i wanna do
i suck at explaining lol
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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>
";

?>
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

oh ok, thanks a bunch
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

You can also do:

Code: Select all

<?php
$username = "Info From DB";
echo "<input type="text" name="username" value="$username">";
?>
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post 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?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post 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
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post 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?
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
Post Reply