Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
PHP is driving me insane, need help [solved]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
-=GGW=- $ol!d $n4>|e
Veteran
Veteran


Joined: 12 Apr 2004
Posts: 1616
Location: USA

PostPosted: Tue Mar 04, 2008 4:58 am    Post subject: PHP is driving me insane, need help [solved] Reply with quote

I figured i'd try to learn some php over last weekend, and i've been able to work around all the kinks but one.

I can't find out how to pass values into a .php file and use them for the life of me.

i have a function defined as

Code:

function calculateHitpoints()
{

      //$feed = isset($_GET['feed']);
      
      $hpsub = (int)((time() - filemtime(DATAFILE)) / DRAIN);
      
      $hp = file_get_contents(DATAFILE);
      
      $hp -= $hpsub;
      
      if ($_GET['feed'] == true)
         $hp += 10;

      if ($hp > MAXHP)
         $hp = MAXHP;

      if ($hp < 1)
         $hp = 1;

      if ($_GET['feed'] == true)
         $handle = fopen(DATAFILE, w);
         fwrite($handle, $hp);
         fclose($handle);

      return $hp;
}


the crazy thing is, nomatter what i do when i call it, 10 gets added to the value of hp. I've tried test.php?feed=true, test.php?feed=fase, test.php?feed=1, test.php?feed=0. NOTHING seems to let me use the bloody variable, any tips? How come that if statement is ALWAYS entered. grrr :x Sorry, its been like 2 hours sifting around the net trying to find out why this wont work.

Also, I get that the way to call a script would be to use a link to the php file maybe, but, i cant find out how to call a script and end up back at the same page, I wanna call it without taking the user there.


Last edited by -=GGW=- $ol!d $n4>|e on Tue Mar 04, 2008 7:46 am; edited 1 time in total
Back to top
View user's profile Send private message
elgato319
Guru
Guru


Joined: 15 Sep 2005
Posts: 546

PostPosted: Tue Mar 04, 2008 7:36 am    Post subject: Reply with quote

Code:

<?PHP
if ($_GET['feed'] == true)
{
  echo "outside";
}

calc_hp();

function calc_hp()
{
  if ($_GET['feed'] == true)
  {
  echo "inside";
  }
}
?>


page.php?feed=true should output "outsideinside".
page.php alone should output nothing.

Quote:

Also, I get that the way to call a script would be to use a link to the php file maybe, but, i cant find out how to call a script and end up back at the same page, I wanna call it without taking the user there.


How about using includes?
http://de2.php.net/manual/en/function.include.php
Back to top
View user's profile Send private message
krinkle
Guru
Guru


Joined: 04 Feb 2003
Posts: 338
Location: Garden Grove, CA

PostPosted: Tue Mar 04, 2008 7:42 am    Post subject: Reply with quote

Quote:

Also, I get that the way to call a script would be to use a link to the php file maybe, but, i cant find out how to call a script and end up back at the same page, I wanna call it without taking the user there.


Depending on exactly what you mean, it sounds like you want some ajax magic... (ajax let's you submit forms and get a return without having to change pages. IBM has a really good primer on their site.)
Back to top
View user's profile Send private message
-=GGW=- $ol!d $n4>|e
Veteran
Veteran


Joined: 12 Apr 2004
Posts: 1616
Location: USA

PostPosted: Tue Mar 04, 2008 7:45 am    Post subject: Reply with quote

Thanks, i was leaving off the parenthesis in the if statements, and also i shouldn't have used is_set. includes did the trick to with include_once(html file) at the end of it, and having imagejpeg output to a file instead of outputting in place of the php. Thanks for the tips. :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum