Results 1 to 3 of 3

Thread: On click display

  1. #1
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default On click display

    Hi everyone. Here is a pretty basic php script.
    Code:
    <html><body>
    
    <form action="order.php" method="post"> 
    
    Name<input name="name" type="text" /> 
    <input type="submit" />
    </form>
    </body></html>
    
    <?php
    $cheese = $_POST['name'];
    
    echo "Welcome ". $cheese . ", to my webpage <br />";
    
    
    ?>
    It does what I want, but is there a way to display the Welcome "name" to my webpage only after the button is clicked.


    Thanks for any help
    Last edited by jscheuer1; 06-25-2011 at 06:19 AM. Reason: format code

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Not entirely sure I understand your question but does this work?

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <title>My Page</title>
    <body>
    <?php
    if (!empty($_POST['name'])) {
    $cheese $_POST['name'];
    echo 
    "Welcome "$cheese ", to my webpage <br />";
    } else {
    ?>
    <form action="order.php" method="post">
    Name:<input name="name" type="text" />
    <input type="submit" />
    </form>
    <?php
    }
    ?>
    </body>
    </html>
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Perfect. Thankyou very much.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •