Web Analytics Made Easy -
StatCounter write forn value - CodingForum

Announcement

Collapse
No announcement yet.

write forn value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • write forn 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; Feb 24, 2004, 03:56 PM.
    Mike

  • #2
    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.

    Comment


    • #3
      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
      Mike

      Comment


      • #4
        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.

        Comment


        • #5
          thanks

          Thanks alot for your help

          Ive now sorted it.
          Mike

          Comment

          Working...
          X