PHP assistance

CivFan91

Emperor
Joined
Sep 1, 2005
Messages
1,589
Location
USA
OK, I'm building a Web-based game. In order to utilize certain functions I always wanted to have, I need to use PHP. No big deal, just another language to learn. Now, I'm trying to set up variables that can be passed from page to page. I assume it works, but I'd never know: the darn echo won't work.

I have set up two pages for testing PHP: test1 and test2. I'm setting up a health system, and want to remove 25 health. OK, my code is:

test1.php
Code:
<?php 
 session_start("healthmeter"); 
 $_SESSION["health"] = 100; 
 ?> 
 <html> 
 <head> 
 <title>Test page for PHP</title> 
 </head> 
 <body> 
 <p><a href="test2.php">Take off 25% health</a></p> 
 <p><?php  
 echo $health; 
 ?> </p>
 </body> 
 </html>

test2.php:

Code:
<?php 
 session_start(); 
 $_SESSION["health"] -= 25;
 ?> 
 <html> 
 <head> 
 <title>Test page for PHP</title> 
 </head> 
 <body> 
 <p><?php 
 echo $health;  
 ?> </p>
 </body> 
 </html>

OK, I get no errors, but I can't get the variable to echo. If I put the variable in quotes, the ECHO works, but obviously it's not the variable I see. If I set up the code nice and pretty, I can't see any numbers. What am I doing wrong?
 
You tried echo $_SESSION['health'];? AFAIK session variables have to be called with $_SESSION. I'm almost certain $health in this case hasn't been declared. ("Almost" because I haven't had much experience in PHP)
 
quentin's right. you need either to first declare $health. something like $health = $_SESSION["health"];

or use echo $_SESSION["health"] directly.
 
CivFan91 said:
Ok, I changed the name of the thread because I am having non-PHP realted questions. My site calls for MySQL. So, I downloaded it and installed it to C:\MySQL. So far, so good. I am running the Windows Apache server and need Apache to "see" the MySQL. How would I do this?

Probably easier just to download a copy of Uniform Server which is a package containing apache, php, perl and mysql, all pre-configured to work "out of the box".
 
Top Bottom