SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Posting variables to PHP via broswer.

    Hello everyone,

    I would highly appreciate it if you someone can point my mistake in this. I have a very simple php script which post a single variable called email. I would like to test the POST method from browser by extending the query string like this:

    http://localhost/email.php?email=&helloworld

    here is my script:
    Code:
    <?php
       
     $email = $_POST['email'];
    echo $email;
    ?>

  2. #2
    SitePoint Enthusiast Mounty's Avatar
    Join Date
    Mar 2008
    Location
    UK
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's $_GET for the query string, or you can use $_REQUEST which combines both post, get and cookie

  3. #3
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello Mounty,

    How can I make sure that a variable is being posted if POST is being used instead of GET, please.

    Thanks.

  4. #4
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think this is what you are asking.
    The code below will only give the variable a value if the GET method is used, which is normally via the url. If the POST method is used the user will receive the no value message.
    Also, be sure to validated the user's input.
    PHP Code:
    $email $_GET['email'];
    if (isset(
    $email) && $email != '') {
     echo 
    $email;
    } else {
    echo 
    'No value given.';


  5. #5
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    23
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ultrajeeps View Post
    How can I make sure that a variable is being posted if POST is being used instead of GET, please.
    You would use this if you wanted to use $_POST...

    PHP Code:
    if(isset($_POST['variable'])){
    echo 
    'Post variable posted.';
    }else{
    echo 
    'Post variable not posted.';

    Or you could do it the shorthand way...

    PHP Code:
    echo (isset($_POST['variable']))? 'Variable posted':'Variable not posted'

  6. #6
    SitePoint Enthusiast Mounty's Avatar
    Join Date
    Mar 2008
    Location
    UK
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ultrajeeps View Post
    Hello Mounty,

    How can I make sure that a variable is being posted if POST is being used instead of GET, please.

    Thanks.

    Use this to check if POST data was sent:

    Code:
    if ($_SERVER['REQUEST_METHOD'] == "POST")
    hope that's some help?

  7. #7
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    NYC
    Posts
    306
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much for all your help.

  8. #8
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you just want to check they are being passed, install Firefox and Firebug extension, which can show you POST requests and the content of variables.


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
  •