Hi,
I am reading a book called PHP/MySQL programing for the absolute beginner and I am trying to get variables to be saved so the next time the program is run that variable has the same value. So I saved the value with:
<input type = "hidden"
name = "randNum"
value = "$randNum">
but it did not work so I tough it was because it was at the end. so put it at the top of the code. Still it did not work. The book has this:
<html>
<head>
<title>Poker Dice </title>
<style type = "text/css">
body {
background: green;
color: tan
}
<style>
</head>
<body>
<center>
<h1>Poker Dice</h1>
<form>
<?
//check to see if this is first time here
if (empty($cash)) {
$cash = 100;
}
rollDice();
if ($secondRoll == TRUE) {
Print "<h2>Second Roll</h2>\n";
$secondRoll = FALSE;
evaluate();
} else {
print "<h2>First Roll</h2>\n";
$secondRoll = TURE
}
printStuff();
function rollDice(); {
//...I would right this but it plays no part in this question and it is to long to write...
}
function evaluate(); {
//...I would right this but it plays no part in this question and it is to long to write...
}
function printStuff() {
Global $cash, $secondRoll;
Print "Cash: $cash\n";
//Store Variables in hidden fields
print <<<HERE
<input type = "hidden"
name = "secondRoll"
value = "$secondRoll">
<input type = "hidden"
name = "cash"
value = "$cash">
HERE;
}
There that works but I can't get my programs to do this. Can some one please tell me what I am not doing. This is my code:
<html>
<head>
<title>I'm Think Of A Number...</title>
</head>
<body>
<form method = "post" action = "program.php">
<?
savedinfo();
print "$test";
function savedinfo() {
global $test;
print <<<HERE
<input type = "hidden"
name = "test"
value = "10">
HERE;
return $test;
}
?>
</form>
</body>
</html>
Also do you need to use the return command on variables that are global?
Thanks A Lot!,
Andrew