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
https://forums.phpfreaks.com/topic/222605-using-_get-and-_post/
Share on other sites

Thanks 182guy,

 

i've corrected the error and tried it again but it still does not work. Do you think it could be soemthing with my php setting because i have encountered this problem in hte past and it always discourages me from continuing to learn phe.

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]

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)

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.