Jump to content

post variable


fortnox007

Recommended Posts

Hi guys, I pretty new to php, and was writing a small script after a I read a chapter (4) about if-statements of a book. But it seems I am doing something wrong. Maybe someone could help me in the right direction.

 

In a nutshell: I have a small form, and when someone presses submit it should go to another page and include the variables of the previous page. So far I am only been able to include html form variables which I recover on the next page with $_POST['xxxx'];

 

here under ill Put a part of my script which is not of any use, but its more for me to understand how to get php variables on the next page. I am using a self referencing script and i have some comments added to read along.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>bla bla bla</title>
    </head>
    <body>
        <?php  
        //code to be executed when monkey button pressed
        if (isset($_POST['monkey'])){        
                echo $_POST[$number1];
                echo 'monkey pressed';
        }
        //code to be executed when snakes button pressed
        if (isset($_POST['snakes'])){        
                echo $_POST[$number1];
                echo 'snakes pressed';
        }
        ?>
        <h1>bla bla bla</h1>
        <h3>
            <?php
            $number1 = $number1.mt_rand(1,100000);
            echo $number1;
            ?>
        </h3>
        <form action="<?php echo $_PHP['PHP_SELF']; ?>" method="post">
            <input type="submit" value="monkey" name="monkey" />
            <input type="submit" value="snakes" name="snakes" />
        </form>

    </body>
</html>


Link to comment
https://forums.phpfreaks.com/topic/209845-post-variable/
Share on other sites

Wow thanks a lot for your swift response.

Would you mind explain a little why not to use <?php echo $_PHP['PHP_SELF']; ?>

I am just starting with php and in the book I bought they say i should use it to let the page self reference.

Is there maybe a security risk when i use it?

If you happen to have time for it i would be extremely pleased. Ill search for session variables

(just 3 chapters away ;-)

 

Thanks man!

 

John

Link to comment
https://forums.phpfreaks.com/topic/209845-post-variable/#findComment-1095408
Share on other sites

Holy crap, I just googled my ass of for don't use  <?php $_SERVER['PHP_SELF']; ?>

and i found loads and loads of blogs about it.

Thanks Alot for pointing me to this. I really apreciate it The only thing i realy hate is that the book i have doesn't say 1 word about it and above all a so called security dude  was one of the authors.  :wtf:

Well if someone knows a good book to write proper and secure php I am all ears! (eyes in this case  ;D )

 

And again thanks m8 for the quick help

 

Link to comment
https://forums.phpfreaks.com/topic/209845-post-variable/#findComment-1095420
Share on other sites

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.