Jump to content


session variables in calculator

  • Please log in to reply
3 replies to this topic

#1 mckooter

  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 August 2006 - 01:43 AM

Okay, i posted this on another forum, then i found this wonderful place (figured web freaks hosted my website so well might as well use their site to help me learn)

Note: Im new but I am trying to learn so if im missing something simple sorry, I have been reading my books to try to learn and this is my first script, it dosent use a database as its a calculator and it wouldt really be feasable.

okay from a recent post of mine i made a session variable, now using these variables i plan to do calculations, by doing that i first call the session to a regular variable (simply because i made the calculation using regular variables)
$aloan1 = $_SESSION['aloan1'];

then that variable is used later in program as a number for a calculation, something like this

$taloan = ($aloan1 + $aloan2 + $aloan3 + $aloan4 + $aloan5 + $aloan6 + $aloan7 + $aloan8 + $aloan9 + $aloan10);

( i realise that is probably the long way of doing something but im learning)

now after getting that $taloan variable i run an if statement on it (something like:)
if ($under10k == "yes" and $vestbal <= 10000)
	$fcalc1 = ($vestbal - $taloan - $tdloan - $taint);
(note there are some variables i did not include above for relevance and legnth of post)

when i process page i get this error:

Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

now after looking at this register_globals I assume mine is turned off because im not getting a result, now does this mean that i cannot use these sessions variables to send data for calculations?

I believe i have confused myself with my first script and hopefully the above post is understandable

#2 hitman6003

  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 02 August 2006 - 01:48 AM

Make sure that you are extracting all of the variables from $_SESSION by doing the:
$aloan1 = $_SESSION['aloan1'];
for each one.

You can also use extract (http://www.php.net/extract) to quickly do that for all of them.

#3 redarrow

  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 August 2006 - 01:50 AM

<form method="get" action="action.php">
Enter the First Number <input type="text" name="number1">
Enter the Second Number <input type="text" name="number2">
Choose the operation
<input type="radio" name="op" value="add" checked>
Addition <input type="radio" name="op" value="sub">
Subtraction <input type="radio" name="op" value="mul">
Multiplication <input type="radio" name="op" value="div">
Division <input type="submit" name="Submit" value="Submit">


if ( $op == "add" ) {  echo "$number1 + $number2 = ";  echo $number1 + $number2;}
if ( $op == "sub" ) {  echo "$number1 - $number2 = ";  echo $number1 - $number2;}
if ( $op == "mul" ) {  echo "$number1 * $number2 = ";  echo $number1 * $number2;}
if ( $op == "div" ) {  echo "$number1 / $number2 = ";  echo $number1 / $number2;}


Wish i new all about php DAM i will have to learn

#4 mckooter

  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 02 August 2006 - 02:00 AM

thank you very much, this quick (i must say i am very impressed and happy to see people so glad to help me out)

anyway, this quick response showed me that it should work, then after looking i realized if i actually called that variable it might show me the result, (simple stupid mistake)

it works now, thanks again, with this info i think i might be able to finish this script once and for all

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users