Can anyone tell me why this program doesnt work properly? Its from a PHP 5 book as well! I copied it from the author's CD, just wondering whats wrong. He says he tries to pass the value in hidden input box. And the value increments by one every time you click the submit button. Any ideas? Thanks.
<html>
<head>
<title>
persistence demo
</title>
</head>
<body>
<h1>Persistence Demo</h1>
<form>
<?
//increment the counters
global txtBoxCounter++;
$txtBoxCounter++;
$hdnCounter++;
print <<<HERE
<input type = "text"
name = "txtBoxCounter"
value = "$txtBoxCounter">
<input type = "hidden"
name = "hdnCounter"
value = "$hdnCounter">
<h3>The hidden value is $hdnCounter</h3>
<input type = "submit"
value = "click to increment counters">
HERE;
?>
</form>
</body>
</html><?php
if (!isset($_POST['counter'])) {$counter = 1;}
else {$counter = $_POST['counter'] + 1;}
echo '
<form action="" method="POST">
The hidden value is ' . $counter . '<br>
<input type="hidden" name="counter" value="' . $counter . '">
<input type="submit" name="submit" value="click to increment counter">
</form>
';
?>Hmmm it seems i made the mistake of not turning on register_globals liek the author wanted, but then isnt that a security breach? Also when this program first starts up, it says there are a couple variables undefined, and they cant be defined until the program is run once.if you are reading a book that suggests turning register_globals ON then you need to get a new book.if you are reading a book that suggests turning register_globals ON then you need to get a new book.
Yes, most definitely Lol really? Its called PHP 5/MySQL for Absolute Beginners. I believe he says its allright for now, testing purposes.Maybe, but why teach bad habits that your students would just have to unlearn later?wow..that code confusing..Thank you; I do my worst
<html>
<head>
<title>
persistence demo
</title>
</head>
<body>
<h1>Persistence Demo</h1>
<form>
<?
//increment the counters
global txtBoxCounter++;
$txtBoxCounter++;
$hdnCounter++;
print <<<HERE
<input type = "text"
name = "txtBoxCounter"
value = "$txtBoxCounter">
<input type = "hidden"
name = "hdnCounter"
value = "$hdnCounter">
<h3>The hidden value is $hdnCounter</h3>
<input type = "submit"
value = "click to increment counters">
HERE;
?>
</form>
</body>
</html><?php
if (!isset($_POST['counter'])) {$counter = 1;}
else {$counter = $_POST['counter'] + 1;}
echo '
<form action="" method="POST">
The hidden value is ' . $counter . '<br>
<input type="hidden" name="counter" value="' . $counter . '">
<input type="submit" name="submit" value="click to increment counter">
</form>
';
?>Hmmm it seems i made the mistake of not turning on register_globals liek the author wanted, but then isnt that a security breach? Also when this program first starts up, it says there are a couple variables undefined, and they cant be defined until the program is run once.if you are reading a book that suggests turning register_globals ON then you need to get a new book.if you are reading a book that suggests turning register_globals ON then you need to get a new book.
Yes, most definitely Lol really? Its called PHP 5/MySQL for Absolute Beginners. I believe he says its allright for now, testing purposes.Maybe, but why teach bad habits that your students would just have to unlearn later?wow..that code confusing..Thank you; I do my worst