echoing PHP vars to HTML

They have: 3 posts

Joined: Oct 2000

I haven't worked with PHP before, but am trying to help some friends edit a PHP chat program so that the username does not have to be re-entered per posting.

This code uses two PHP programs - one to process the post and include the other which presents the posts/input form.

I created a var $username in the processing program, and set it equal to the user's input in the name field, but am unsure how to write this back in the other script.

The code in the 'write back' script is echoing HTML - which leads me to wonder if this statement within those echos will crash:

I would think I at least need a way to send quotes...
but I just don't know enough about PHP to formulate this.

Anybody, got a quick answer for this easy question?

Thanks, Carolyn

They have: 850 posts

Joined: Jul 1999

You could do something like this:

<?
php
code
here
?>
">
<?
more
php
code
?>

They have: 3 posts

Joined: Oct 2000

Thanks so much, Rob.

That would make this line in full read:

echo "">\n";

My friends and I sure appreciate your help.

- Carolyn

They have: 850 posts

Joined: Jul 1999

Almost Smiling
PHP is great because you can basically 'end' and 'start' it whenever you want inside a .php(3) file.

So
just using:
">
this would 'start' PHP, print $username, and than 'end' it.

So you could have:

<?
$username = 'rob';
?>
<input type="text" name="name" value="<?echo $username?>">
<?
more
php
code
?>
'

You could also use

<?
$username = 'rob';
echo "<input type=\"text\" name=\"name\" value=\"$username\">";
?>
'
But the prior method is much easier I find (especially if you are printing a lot of html)

[Edited by Rob Pengelly on 10-30-2000 at 09:33 PM]

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

this may be too advanced, but have you thought about haveing users 'login' and 'logout' and use session variables to store the username and password?

Mark Hensler
If there is no answer on Google, then there is no question.

They have: 3 posts

Joined: Oct 2000

Thank you both. Rob, I've gone with version two....
and as for session variables - well, they just whizzed right by, but thanks for the thought.

- Carolyn

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.