Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post

    write form value

    I was wondering if it is possible to write a form variable from the url bar?

    My basic script is:
    <?php
    if ($_POST["name"] == 1)
    echo "you typed mike";
    elseif ($_POST["name"] == 2)
    echo "you typed 2";
    else
    echo "wrong";
    ?>

    And i want to set the 'name' value with the URL in the address bar.
    Is it possible
    Thanks for any help
    Last edited by anarchy3200; 02-24-2004 at 08:56 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If it's from the url, you should probably use $_GET instead of $_POST.

    If you'd like to cycle through all the variables in the url, I think you can do something like:

    PHP Code:
    foreach($_GET as $var => $val) {
     echo 
    $var."=".$val."<br>";

    Hope that helps,
    Sadiq.

  • #3
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post
    thanks for that as it was useful for something else but i didn't explain very well,

    i want to set the 'name' value from the url bar eg

    www.site.com/page.php?name=mike

    the above is just an example but is there a way to do this?

    thanks

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think it has something to do with some of your PHP settings, like $GLOBALS on or something... check your php.ini

    If you have GLOBALS as on, then you can reference it as $name, and you don't have to set any values.

    I'm pretty sure using $_GET["name"] would do the same thing though.. anyone feel free to correct me if I'm wrong.

    So just to re-write that, if you've got your GLOBALS on then you can start referencing $name without declaring it or anything if it's in the url like you've specified.

    I think you can also use $_GET["name"] to get its value. I think there are some security issues with accepting variables from the url, but if you're not building an application where security is an issue then I don't think it should be a problem.

    Hope that helps,
    Sadiq.

  • #5
    Regular Coder anarchy3200's Avatar
    Join Date
    Mar 2003
    Location
    England
    Posts
    261
    Thanks
    0
    Thanked 1 Time in 1 Post

    thanks

    Thanks alot for your help

    Ive now sorted it.


  •  

    Posting Permissions

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