# Everything works except variables through the browser

**URL:** https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135
**Category:** programming
**Created:** [September 23, 2004, 9:00am UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135 "2004-09-23T09:00:09Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![flashyjoe](https://avatars.discourse-cdn.com/v4/letter/f/9e8a1a/32.png) [@flashyjoe](https://forum.kirupa.com/u/flashyjoe)
#### Post date: [September 23, 2004, 9:00am UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135/1 "2004-09-23T09:00:09Z")

</div>

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](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!!!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 23, 2004, 9:58pm UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135/2 "2004-09-23T21:58:12Z")

</div>

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

```php

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 23, 2004, 10:17pm UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135/3 "2004-09-23T22:17:37Z")

</div>

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' or`T\_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…

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 24, 2004, 6:35am UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135/4 "2004-09-24T06:35:39Z")

</div>

something like this:

```php

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

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 24, 2004, 8:33am UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135/5 "2004-09-24T08:33:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 27, 2004, 4:47pm UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135/6 "2004-09-27T16:47:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [September 28, 2004, 4:05am UTC](https://forum.kirupa.com/t/everything-works-except-variables-through-the-browser/65135/7 "2004-09-28T04:05:37Z")

</div>

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](https://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]”;  
?\>
