Everything works except variables through the browser

I am running Apache 1.3.2 and PHP 4.3.2 . and MySQL and everything seems to work, I can even connect to the database but when I try to pass a simple variable through the browser a parsing error on line 9 or I get a blank page?
for example:
8 <body>
9 <?php echo*“Hello, $username”; ?>
10 </body>

when I type the username on the url, or even through a form nothing comes up.
http://localhost/test.php?username=flashy

I get just Hello

this works fine:
<body>
<?php phpinfo(); ?>
</body>

Can’t figure it out…
Any help would be appreciated!!!

If you’re trying to get the variable from the url then you need to use the globals array:


8 <body>
9 <?php echo "Hello, $_REQUEST['username']"; ?>
10 </body>

I use request because it references both post and get variables, although you could use:

$_POST[‘username’]

or

$_GET[‘username’]

Your code probably doesn’t have a value assigned to $username.

This is the form I use… on form.php page, then

<form method=“get” action=“test.php”>
Enter your name: <input type=“text” name=“username”>
<br><input type=“submit” value=“Print it”></form>

with your code on test.php,
<body>
<?php echo “Hello, $_REQUEST[‘username’]”; ?>
</body

I get this…
Parse error: parse error, expecting T_STRING' orT_VARIABLE’ or `T_NUM_STRING’ in /Users/frank/Sites/MySampleApp/test.php on line 8

what am I doing wrong… I want to get this simple thing to work, so I can move on to other stuff…

something like this:


<?php
echo "Hello, " . $_REQUEST['username'];
?>

d’oh… yeah like that. Better not to put variables inside a string. Makes them easier to see with syntac highlighting programs too.

There we go!!! Thanx njs12345. That thing was driving me nuts. At least now I know it was syntax that was wrong instead of trying to figure out if my php pages were bring processed. Thanks for the help, simple but very useful info.

One more thing, instead of posting a new thread. This code is from one of the tutorials in conneting to a database through flash. But, when I try it (with my database info of course). I get parsing errors. Could it be the same reason discussed above? Better not to put variables inside a string.

<?php
//read.php
//prints contents of content column where filename = $file

if($file) {
$link = mysql_connect(dbhost, dbuser, dbpassword)
or die("<b>error</b>: failed to connect to database");

$query = “SELECT content FROM files WHERE filename=’$file’”;
$result = mysql_query($query)
or die("<b>error</b>: failed to execute query <i>$query</i>");

mysql_close($link);

$desiredContent = mysql_fetch_array($result, MYSQL_ASSOC);

mysql_free_result($result);

print “content=$desiredContent[content]”;
?>