Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

easy question on variables

Links for php scripts

Moderators: macek, egami, gesf

easy question on variables

Postby icu90ucme » Wed Aug 06, 2003 9:23 am

im trying to pass this variable through this link

Code: Select all
<td>Suspended <a href="take_off_suspension.php?username=$usr[username]">Take off</a></td>

on the take_off_suspension.php page i have
Code: Select all
  $username = $HTTP_GET_VARS['username'];
  echo $username;

the result that is echo'd is "$usr[username" instead of the actual value... does anybody know a fix
New php-forum User
New php-forum User
Posts: 23
Joined: Mon Jul 07, 2003 2:29 pm

Postby swirlee » Wed Aug 06, 2003 10:11 am

First, of all, you're calling your array element wrong. When specifying an associative index, the index must be specified as a string, e.g. between quotation marks:

Code: Select all
   $arr = array('a' => 1, 'b' => 2);

   // this is very wrong:
   echo $arr[a];

   // this is correct:
   echo $arr['a'];   

Doing it without the quotes still works, but it's deprecated functionality and should never be done. You can read about it in the "Array do's and don'ts" section on this page.

Secondly, I think your problem is that you're trying to access a variable from outside PHP. PHP ignores everything that isn't between <? and ?> tags. So, instead of this:

Code: Select all
<a href="take_off_suspension.php?username=$usr[username]">Take off</a>

You want this:

Code: Select all
<a href="take_off_suspension.php?username=<? echo $usr['username']; ?>">Take off</a>

Or you can use the short syntax:

Code: Select all
<a href="take_off_suspension.php?username=<?= $usr['username'] ?>">Take off</a>
User avatar
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.