Hello World help

Discussion in 'PHP' started by IanT, Feb 26, 2010.

  1. #1
    Okay, I figured out how to print hello world, now I want to build on this, but cant find tutorials to do so because I dont know what the function is called. I want to be able to have something that gives me the option to type in "hello world" in the browser, and then have it return "hello world", or whatever else I input into it...

    (like if I input Whats up!, it says Whats up! rightback...)

    I dont know what this script is called!

    Thanks! :)
     
    IanT, Feb 26, 2010 IP
  2. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #2
    Do you mean something like:
    <?php
    	if($_POST['submit'] && !empty($_POST['text']))
    	{
    		echo $_POST['text'];
    	} else {
    		echo "<form method='POST'>Text: <input type='text' name='text'><br /><input type='submit' name='submit'></form>";
    	}
    ?>
    PHP:
     
    CoreyPeerFly, Feb 26, 2010 IP
  3. IanT

    IanT Well-Known Member

    Messages:
    503
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #3
    precicesly!

    Thank you... okay I need to learn about how/why it does what it does now cause that is much different than

    <?php
    print "hello world
    ?>

    also just curious,

    when I run that code it says this:

    does that just mean that it deosnt have anywhere to submit it to so its like wooooah what is going on here? (is that an error, or just a note saying that there is nowhere for the input to be stored, except to spit it back out at you)

    Edit to add:

    this may sound like a realllly dumb question but how do you make these symbols:

    ||
     
    IanT, Feb 26, 2010 IP
  4. CoreyPeerFly

    CoreyPeerFly Notable Member Affiliate Manager

    Messages:
    394
    Likes Received:
    24
    Best Answers:
    5
    Trophy Points:
    240
    #4
    The code below will fix that error.
    <?php
    	if(isset($_POST['submit']) && !empty($_POST['text']))
    	{
    		echo $_POST['text'];
    	} else {
    		echo "<form method='POST'>Text: <input type='text' name='text'><br /><input type='submit' name='submit'></form>";
    	}
    ?>
    PHP:
    The | character is right below the backspace key.
     
    CoreyPeerFly, Feb 26, 2010 IP
  5. IanT

    IanT Well-Known Member

    Messages:
    503
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    130
    #5
    You rock!!!

    (omg feeling like a doof, I didnt know that key existed ! lol)

    Now , why was it showing that error before and not now?

    The only thing I think that changed was the " isset" part... I have noooo idea what that is or what it does lol

    (thanks for all your help!)
     
    IanT, Feb 26, 2010 IP
  6. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #6
    It's because the string had no value to it. isset is checking that the string has a value before beginning to do the work.
     
    HuggyStudios, Feb 27, 2010 IP