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?
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.
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.
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.
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?
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
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.
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 ?>
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?
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:
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
You missed ";" after $user['username']. <input type="text" name="name" value="<?php echo $user['username'] ?>">
<?php echo $user['username'] ?> Code (markup): The above is fine as theres only one statement between the opening and closing tags.