Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 16th, 2004, 02:24 PM
Authorized User
 
Join Date: Feb 2004
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simple Form Submission

I have two textboxes to input data(data.php) and i want to display the data on the other form(show.php) by using POST or GET Method.Im a beginner in PHP, just give me a simple example....thanx

   CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
__________________
   CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
 
Old July 16th, 2004, 02:32 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default


<form action='show.php' method='post'>
<input type='text' name='text1'/><br/>
<input type='text' name='text2'/><br/>
<input type='submit' value='display'/>
</form>


<?php
//if the method of the form is post, use $_POST. otherwise use $_GET
echo $_POST['text1'];
echo "<br/>";
echo $_POST['text2'];
?>

HTH,

Snib

<><
 
Old July 17th, 2004, 04:48 AM
Authorized User
 
Join Date: Feb 2004
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx a lot for your help.I tried some other examples in a book named Mastering PHP that i'd like to discuss with you.
They are as follows:

<html>
    <head><title></title></head>

<body>
    <form action="you_are_adv.php" method ="GET">
        Please fill in the following fields:</br>

        <?php
            $favourite_lang="PHP";


        ?>
        <b>First Name:</b>
        <input type="text" name="first" value="<?php print($first); ?>" size="15"><br/>

        <b>Last Name:</b>
        <input type="text" name="last" value="<?php print($last); ?>" size="15"><br/>

        <b>Favourite Programming Language:</b>
        <input type="text" name="favourite_lang" value="<?php print($favourite_lang); ?>" size="15"></br>

        <input type="submit" value="Go!" size="15">

    </form>
</body>
</html>


<html>
    <head><title></title></head>
    <body>
        Hello<b><?php print($first . " " . $last);?></b>

        I am glad to know your favourite programming language
        is<?php print($favourite_lang); ?>

        <?php
        $query_string="";
        $query_string .= "?first" .urlencode($first);
        $query_string .= "&last=" .urlencode($last);
        $query_string .= "&favourite_lang=" .urlencode($favourite_lang);
        ?>
        <br/><br/>
        <a href="who_are_you_adv.php<?php print($query_string) ?>">
        Back to who are you advanced
        </a>
    </body>
</html>
The output was something like this after entering text and clicking the submit(GO) button:
(Hello I am glad to know your favourite programming language is

Back to who are you advanced)
And in the adress bar of the you_are_adv.php page i see the following:
(http://127.0.0.1/you_are_adv.php?fir...urite_lang=PHP)

Now what is really going on?
What is the importance of urlencode???
Waiting for your reply...

   CEO
InteliSoft

Maqsood ur Rahman
Life:An Endless Journey towards Perfection
 
Old July 17th, 2004, 06:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, urlencode (http://uk2.php.net/manual/en/function.urlencode.php) will replace any prohibited characters in a querystring, like a space, with their escaped equivalents (so, that a querystring of '?first=William&last=Arbuthnal Higgin' becomes '?first=William&last=Arbuthnal%20Higgins'). You must retrieve the values you sent from the submission form by assigning them to local variables (via $first=$_GET['first'], and so on). Since the browser would have urlencoded the values sent from the form, anyway, you will have to make a call to urldecode (http://uk2.php.net/manual/en/function.urldecode.php), to cater for the 'William Arbuthal Higgins'es of this world, as in:
$last = urldecode($_GET['last'];

HTH
Take it easy,
Dan





Similar Threads
Thread Thread Starter Forum Replies Last Post
form submission...help!? mdbrueckner ASP.NET 2.0 Basics 1 September 19th, 2007 06:16 PM
C# reset of checkbox after form submission booksnore2 General .NET 5 July 29th, 2004 10:30 AM
Form Submission - Instant Answer anshul Pro PHP 2 April 23rd, 2004 03:57 PM
conditional form submission moushumi Classic ASP Basics 1 March 30th, 2004 08:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.