[web] PHP HELP

Started by
2 comments, last by markr 18 years, 10 months ago
I can't seem to figure out why these functions don't work like they should work. Can someone help me? <html> <?php echo $mark; session_start(); if ($_POST["action"] == "Previous 20") { $mark = $mark - 20; } if ($_POST["action"] == "Next 20") { $mark = $mark + 20; } if ($_POST["action"]) { ?> <script>window.location="<?php echo $PHP_SELF?>?mark=<?php echo $mark?>"</script> <? } ?> <body> <form method="post" action="<?php echo $PHP_SELF?>"> <input type=submit name="action" value="Next 20"> <input type=submit name="action" value="Previous 20"> </form></body></html>
Advertisement
You must use session_start() before you send anything to the browser, like your opening html tag.
Quote:Original post by Invader X
You must use session_start() before you send anything to the browser, like your opening html tag.
To add to this: anything includes whitespace, which can catch you out. I also reckon <?php echo $PHP_SELF?> should be <?php echo $_SERVER['PHP_SELF']; ?> (I don't know if that would break, though). Forms will sumbit to the page they are on if you don't specify an action parameter, too.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

You can't just use $mark and imagine that it will somehow magically be preserved between pages.

Use $mark = $_REQUEST['mark'] or something similar. Add "mark" as a hidden field to the form.

Ensure that register_globals is off - it's a misfeature and will confuse you and break your apps in subtle and dangerous ways.

Mark

This topic is closed to new replies.

Advertisement