PHP in Textarea

Discussion in 'PHP' started by bstunt, May 10, 2008.

  1. #1
    I'm trying to make a shoutbox on mysite, and I really don't have much experience when it comes to PHP.

    I'm trying to make the Username show up on the text area field. This is what I have so far..

    But when I view the page, nothing is showing up.

    Anyone know the problem/right code?
     
    bstunt, May 10, 2008 IP
  2. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Most likely your server has programming errors logged.

    Try
    
    <input type="text" name="name" value="<?php echo $user['username']; ?>">
    
    PHP:
    EDIT: Probably not a good idea to name something "name" either -- it'll just cause problems.
     
    TeraTask, May 10, 2008 IP
  3. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #3
    maybe the $user isn't working try puting it in a var_dump($user) and it will tell you if it's NULL or not.
     
    clinton, May 10, 2008 IP
  4. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try this

    <input type="text" name="name" value="<? print $user['username']; ?>" />
    PHP:
     
    cornetofreak, May 11, 2008 IP
  5. clinton

    clinton Well-Known Member

    Messages:
    2,166
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    110
    #5
    I don't thik that would make a difference. doesn't hurt to give it a try.

    going like this is my fav, but you have to have short tags turned on in php.ini
    <input type="text" name="name" value="<?= $user['username'] ?>" />
    PHP:
    I use it all the time for forms.
     
    clinton, May 11, 2008 IP
  6. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The version I posted will work on more servers than those which followed. Be wary of those who cut out bits of code without fully understanding the consequences. Question: What if PHP short tag support wasn't enabled?
     
    TeraTask, May 11, 2008 IP
  7. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    i agree with teratask theres several ways to wiriting php shot and long ways but they do have some effect depending on the server / mysql and php versions
     
    cornetofreak, May 11, 2008 IP
  8. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #8
    Looks like your working with an array there.
    Could we take a look to see how the array is created? That might be the issue.
     
    nabz245, May 11, 2008 IP
  9. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #9
    Yeah... var_dump $user to see if 'username' exists within it.

    As for putting ';' in the short statements it doesn't really seem to matter unless you put more than one statement between the <?php and ?>
     
    chopsticks, May 11, 2008 IP
  10. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Short tags don't always require a semicolon.

     
    TeraTask, May 11, 2008 IP
  11. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #11
    I use short tags all the time and it's never been a problem.
     
    nabz245, May 11, 2008 IP
  12. TeraTask

    TeraTask Peon

    Messages:
    37
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I walk across the street all the time w/o looking and haven't been hit by a car.
     
    TeraTask, May 11, 2008 IP
  13. bstunt

    bstunt Well-Known Member

    Messages:
    385
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    110
    #13
    well... sorry guys but this one worked. lol....

    another question...

    is there anyway I can show the textbox (or part of the page) only when the user is signed on?
     
    bstunt, May 13, 2008 IP
  14. Perow

    Perow Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    If you wish to accomplish that, you should have a login system that stores a session variable that indicates whether the user is logged in or not.

    On your login form, you could put the following:
    
    //At the very top of the page:
    session_start();
    
    //anywhere:
    if(/*logged in successfully*/)
      $_SESSION['loggedin'] = true;
    
    PHP:
    Then on the page where you want to display the textbox, put this:
    
    //at the very top of the page:
    session_start();
    
    //anywhere:
    if($_SESSION['loggedin']){
        echo "Your textbox here";
    }
    
    PHP:
     
    Perow, May 13, 2008 IP
  15. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #15
    thanks bstunt you are welcome mate i love it when im right lol

    Stick to this forum and you are always helped mate

    good luck with your script

    O and clinton i think it does make a diff when using certain array formats

    peace
     
    cornetofreak, May 13, 2008 IP
  16. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #16
    hold on lol u ow me $5 lmao dont wory were here to help lol
     
    cornetofreak, May 13, 2008 IP
  17. tomazinis

    tomazinis Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    You missed ";" after $user['username'].
    <input type="text" name="name" value="<?php echo $user['username'] ?>">
     
    tomazinis, May 14, 2008 IP
  18. msaqibansari

    msaqibansari Peon

    Messages:
    84
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #18
    each statement should be closed with ; and you don't have written ; after echo statement.
     
    msaqibansari, May 14, 2008 IP
  19. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #19
    <?php echo $user['username'] ?>
    Code (markup):
    The above is fine as theres only one statement between the opening and closing tags.
     
    nabz245, May 14, 2008 IP
  20. cornetofreak

    cornetofreak Peon

    Messages:
    170
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #20
    lol tell em nabzy
     
    cornetofreak, May 14, 2008 IP