Jump to content

Using $_GET and $_POST


bolaowoade

Recommended Posts

Hi guys i am a PHP newbie trying to learn from the beginning. I am reading a php book and i can't get past a particular example because $_GET and $_POST just won't work. Below is the code i am working with:

 

HTML File

<form action="welcome1.php" method="get">

    <div>

    <label for="firstname">First name: <input type="text" name"firstname"

      id="firstname"/></label>

    </div>

    <div>

        <label for="lastname">

            Last name: <input type="text" name="lastname" id="lastname"/>

        </label>

    </div>

    <div>

        <input type="submit" value="GO" />

    </div>

 

PHP file

 

<?php

$firstname = $_GET['firstname'];

$lastname = $_GET['lastname'];

print 'Welcome to our website, ' .

    htmlspecialchars($firstname, ENT_QUOTES, 'UTF-8') . ' ' .

    htmlspecialchars($lastname, ENT_QUOTES, 'UTF-8') . '!';

?>

 

I am working on a windows pc with Vista home edition installed. I run a localhost server installed via XAMMP. Please this has been a recurring problem for me. Each time i get to this stage in the past i always get stuck. $_GET and $_POST just does not work for me. Please heeeelp!

Link to comment
Share on other sites

Your <label> tags should also be closed before opening the <input> tags. Try this:

 

<form action="welcome1.php" method="get">
    <div>
     <label for="firstname">First name: </label><input type="text" name="firstname" id="firstname" />
    </div>
    <div>
        <label for="lastname">Last name: </label><input type="text" name="lastname" id="lastname" />
    </div>
    <div>
        <input type="submit" value="GO" />
    </div>
</form>

 

Then, if it still doesn't function as expected, put this immediately after the opening <?php tag in welcome1.php to see exactly what is in the $_GET array.

echo '<pre>';
print_r($_GET);
echo '<pre>';

[/code]

Link to comment
Share on other sites

Thanks pica, i didnt know people would be so stupid to port mac soft on windows even tho native version is available.. and </form> closing tag didnt really matter to code functionality... its just malformed. (and same applies to label and input tags)

 

and what comes to your new code: works just fine when the double dollar sign is replaced by just one. (as it should  :D)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.