Jump to content

session variables in calculator


mckooter

Recommended Posts

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)
[code]$aloan1 = $_SESSION['aloan1'];[/code]

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

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

( 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:)
[code]if ($under10k == "yes" and $vestbal <= 10000)
{
$fcalc1 = ($vestbal - $taloan - $tdloan - $taint);
}[/code]
(note there are some variables i did not include above for relevance and legnth of post)



when i process page i get this error:

[quote]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[/quote]

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
Link to comment
https://forums.phpfreaks.com/topic/16278-session-variables-in-calculator/
Share on other sites

[code]

<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">
</form>

[/code]


[code]
<?php

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;}

?>

[/code]
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.