help with register globals

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kd81
Forum Newbie
Posts: 2
Joined: Thu Jan 28, 2010 9:20 pm

help with register globals

Post by kd81 »

Hello all, I am very new to php and am having difficulty with a very simple form. When I upload the page with register_globals off, it works fine. I know that register_globals should be turned on and so I added some code to the page and turned them on, but can't seem to get the code to work. This is supposed to be a very simple project for a class, but has kept me busy for hours. Any suggestions would be greatly appreciated.

Thank you. I've posted the code below

Code: Select all

 
<html>
<head>
    <title>The Count</title>
    <style type="text/css">
        @import url("style.css");
    </style>
</head>
 
<body>
    <div id="main">
        <div id="left">
        
        </div>
        <div id="top">
        
            <h1 class="largeText">The number you chose is...</h1>
            <img class="imageFloat" src="images/count.png   " />
            <div id="right">
            <?php
                $whatNumber = $_POST['whatNumber'];
                echo $whatNumber;
            ?>
            </div>
        </div>
        
        <div id="bottom">
        
        <form method="POST">
            <h2>Choose any number, positive or negative.</h2>
            <input type="text" name="whatNumber" size="10" maxlength="10">
            <h2>Choose a method of counting</h2>
            <select name="choose">
                <option value = "f">Count using a for loop</option>
                <option value = "fe">Count using a for each loop</option>
                <option value = "w">Count using a while loop</option>
            </select>
        
            <input type="submit" value="Start Counting">
        </form>
    
        
        <?php   
            $whatNumber = $_POST['whatNumber'];
            $count = 0;
            switch($choose){
                case "w" :
                    if ($whatNumber >=0) {
                    while ($count <= $whatNumber) {
                        echo $count."\n";
                        $count++;
                        }
                    }else if ($whatNumber<=0) {
                    while ($count >= $whatNumber) {
                        echo $count."\n";
                        $count--;
                        }
                    }
                break;
                case "f":
                    for ($count=0; $count <= $whatNumber; $count++) {
                        echo $count."\n";
                        }
                    for ($count=0; $count >= $whatNumber; $count--) {
                        echo $count."\n";
                        }
                    break;
                case "fe":
                    $numbers = range(0,$whatNumber);
                    foreach ($numbers as $number) {
                        echo $number."\n";
                    }
                    break;
            }
        ?>
 
    </div>
</body>
 
</html>
 
kd81
Forum Newbie
Posts: 2
Joined: Thu Jan 28, 2010 9:20 pm

Re: help with register globals

Post by kd81 »

Nevermind. I figured it out from another post.
Just had to put this code in
foreach($_POST as $key => $val)
$$key = $val;

thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: help with register globals

Post by requinix »

kd81 wrote:I know that register_globals should be turned on
No. No. No. Leave it off and learn to code properly without it.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: help with register globals

Post by Luke »

Please use the [ php ] tags when posting php code in the future. I have edited your post to reflect how we'd like to see it posted.

Also, who in the world told you that register_globals should be on? register_globals is the worst thing that has ever happened to PHP. The WORST thing. Never EVER turn it on. Under any circumstance.
Post Reply