PHP Variables

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
alanpollenz
Beginner
Beginner
Posts: 7
Joined: Fri Dec 08, 2006 10:08 pm

PHP Variables

Post by alanpollenz »

I have been through the forums this evening trying all the solutions to this problem. For the life of me, I cannot get a php variable into the menu.

Here is the code from my main page:

Code: Select all

<!-- START NAVIGATION -->
<? print $this_first_name.'<br>'; ?>
						<script src="<? echo $baseurl; ?>/js/milonic_src.js" type=text/javascript></script>
						<script type="text/javascript">
							<!--
							if(ns4)_d.write("<scr"+"ipt src=<? echo $baseurl; ?>/js/mmenuns4.js type=text/javascript><\/scr"+"ipt>");		
							else _d.write("<scr"+"ipt src=<? echo $baseurl; ?>/js/mmenudom.js type=text/javascript><\/scr"+"ipt>"); 
							 -->
						</script>
						<script src="<? echo $baseurl; ?>/include/menu.data.php" type=text/javascript></script>	

<!-- END NAVIGATION -->
As you can see, I renamed menu_data.js to menu.data.php (I also tried menu_data.php. The print statement is there to show that the variable I want to pass does exist. I have the following in my menu.data.php file:

Code: Select all

aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name=<?php echo $this_first_name; ?>;");
When I mouseover the 'Home" menu item, the following is the link displayed in the status bar and the link you are taken to when the menu item is clicked:

http://www.newwaveswimteam.org/index.php?name=

The php variable is not appended to the URL.

If you want to see this in action, I have created a test user with the first name Test and last name User. You can log in at http://www.swimteammanager-dev.com with username testuser and password testuser. You will see the menu with the name Test just above the menu. This is from the print statement in the first codesnippet.Mouseover and then click on Home. You'll see that the frst name is not appended to the url even though it does exist.

Any help would be greatly appreciated.

Alan Pollenz
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Re: PHP Variables

Post by Ruth »

Hi,

OK, this is not something I know much about, but I downloaded your page, renamed the menu.data.php to menu_data.php [only because that's how I've always seen it, I don't know if it makes a difference] Then I change the Home aI string to

Code: Select all

aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name='<?php echo $this_first_name; ?>';");
I saved that page I downloaded as .htm and I don't know if or why that would make a difference, but figured I'd tell you. Anyway, when I opened the page I saved with the new data file and clicked the home item I went to a page showing the menu at the left and then in the center top area had this.

Your location: Home
On the Crest of the Wave
Bring in a Toy

I don't know what the address bar is supposed to show, but in FF it showed

Code: Select all

http://www.newwaveswimteam.org/index.php?name='%3C?php%20echo%20$this_first_name;%20?%3E'
As I said I don't know about this stuff, so I don't know what it's supposed to be, but I did get to a page :)

Ruth
alanpollenz
Beginner
Beginner
Posts: 7
Joined: Fri Dec 08, 2006 10:08 pm

Re: PHP Variables

Post by alanpollenz »

Hi Ruth,

That did not work, but thanks for the suggestion. The reason the address bar showed "http://www.newwaveswimteam.org/index.ph ... me;%20?%3E'" is because with the single quotes around <?php echo $this_first_name; ?> php reads $this_first_name as a literal string not a variable. Also, it looks like the browser replaced the $ and spaces.

If it were working properly and you were logged in as testuser and clicked the "Home" menu item, it should take you to http://www.newwaveswimteam.org/index.php?name=Test

Thanks again.

Alan
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Re: PHP Variables

Post by Ruth »

Hi,

You have this as the url in your menu_data.php file when I go to the dev section to try and test it

Code: Select all

http://www.newwaveswimteam.org/index.php?name=


Doesn't it need the variable?

Code: Select all

<? echo $this_first_name; ?>;
I am going to pass this on to Milonic since I don't know why it isn't working. I did find one post about variables back in January, but don't know if this will help. viewtopic.php?p=40983#p40983

Ruth
alanpollenz
Beginner
Beginner
Posts: 7
Joined: Fri Dec 08, 2006 10:08 pm

Re: PHP Variables

Post by alanpollenz »

Hi Ruth,

The actual line from the menu_data.php file is

Code: Select all

aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name=<?php echo $this_first_name; ?>;");
I have tried it both that way and as follows:

Code: Select all

aI("text=Home;url=http://www.newwaveswimteam.org/index.php?name=<? echo $this_first_name; ?>;");
The reason it appears to end after name= is because the PHP variable is not being parsed for some reason. I have looked at the thread you included but nothing jumps out. It appears as though I am following the correct procedures, just without success.

Alan
alanpollenz
Beginner
Beginner
Posts: 7
Joined: Fri Dec 08, 2006 10:08 pm

Re: PHP Variables

Post by alanpollenz »

Interestingly, if I changed the way the script is called from:

Code: Select all

<script src="/include/menu_data.php" type=text/javascript></script>
to:

Code: Select all

<? include ($basedir.'include/menu_data.php'); ?>
And place <script type="text/javascript"> at the start of menu_data.php and </script> at the end of menu_data.js, it works fine. The only problem, and this is what I'm really trying to avoid, is that when it is called as a php include all the menu_data.php code is displayed in the page source and I want to avoid this. When called as a js file the page menu_data.php code is not displayed in the page source.

Alan
Post Reply