problem with sending value to php page via url - HELP!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ToMeK

    problem with sending value to php page via url - HELP!

    Hi!

    i have php page that displays records from mysql base.
    on that page i have link like this:

    <a href="mypage.ph p?option1">opti on1</a>

    ("option1" is name of one of my tables in db)

    now i want to load that page and assign this value "option1" as string to
    my variable "table".
    I tried this:


    $table=$_SERVER['QUERY_STRING'];
    $query_rs_komp = "SELECT * FROM " . $table;

    but it fills my $table var with "database.optio n1", and i need only
    "option1"

    Also i'll need help with checking if anything was sent to page anyway - so
    if it's first time someone opens page, default value is assigned to var
    $table.

    please if anyone has idea?


  • Pedro Graca

    #2
    Re: problem with sending value to php page via url - HELP!

    ToMeK wrote:[color=blue]
    > i have php page that displays records from mysql base.
    > on that page i have link like this:
    >
    > <a href="mypage.ph p?option1">opti on1</a>[/color]

    <a href="mypage.ph p?db=option1">o ption1</a>
    [color=blue]
    > ("option1" is name of one of my tables in db)
    >
    > now i want to load that page and assign this value "option1" as string to
    > my variable "table".
    > I tried this:
    >
    >
    > $table=$_SERVER['QUERY_STRING'];[/color]

    $table = isset($_GET['db']) ? $_GET['db'] : 'default_table' ;
    [color=blue]
    > $query_rs_komp = "SELECT * FROM " . $table;
    >
    > but it fills my $table var with "database.optio n1", and i need only
    > "option1"
    >
    > Also i'll need help with checking if anything was sent to page anyway - so
    > if it's first time someone opens page, default value is assigned to var
    > $table.[/color]

    HTH
    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    • Tim Van Wassenhove

      #3
      Re: problem with sending value to php page via url - HELP!

      In article <2g1hpeF3eka5U2 @uni-berlin.de>, Pedro Graca wrote:[color=blue]
      > ToMeK wrote:[color=green]
      >> i have php page that displays records from mysql base.
      >> on that page i have link like this:
      >>
      >> <a href="mypage.ph p?option1">opti on1</a>[/color]
      >
      ><a href="mypage.ph p?db=option1">o ption1</a>
      >[color=green]
      >> ("option1" is name of one of my tables in db)
      >>
      >> now i want to load that page and assign this value "option1" as string to
      >> my variable "table".
      >> I tried this:
      >>
      >>
      >> $table=$_SERVER['QUERY_STRING'];[/color]
      >
      > $table = isset($_GET['db']) ? $_GET['db'] : 'default_table' ;[/color]

      If the man requests page.php?option $_GET will be empty.
      But when i test here, $_SERVER['QUERY_STRING'] contains 'option'

      With page.php?option =page1 will fill $_GET['option'] with 'page1'


      --

      Comment

      • ToMeK

        #4
        Re: problem with sending value to php page via url - HELP!

        "Tim Van Wassenhove" <euki@pi.be> wrote in message
        news:2g1k7cF2sh e7U2@uni-berlin.de...[color=blue]
        > In article <2g1hpeF3eka5U2 @uni-berlin.de>, Pedro Graca wrote:[color=green]
        > > ToMeK wrote:[color=darkred]
        > >> i have php page that displays records from mysql base.
        > >> on that page i have link like this:
        > >>
        > >> <a href="mypage.ph p?option1">opti on1</a>[/color]
        > >
        > ><a href="mypage.ph p?db=option1">o ption1</a>
        > >[color=darkred]
        > >> ("option1" is name of one of my tables in db)
        > >>
        > >> now i want to load that page and assign this value "option1" as string[/color][/color][/color]
        to[color=blue][color=green][color=darkred]
        > >> my variable "table".
        > >> I tried this:
        > >>
        > >>
        > >> $table=$_SERVER['QUERY_STRING'];[/color]
        > >
        > > $table = isset($_GET['db']) ? $_GET['db'] : 'default_table' ;[/color]
        >
        > If the man requests page.php?option $_GET will be empty.
        > But when i test here, $_SERVER['QUERY_STRING'] contains 'option'[/color]

        thanks it looks like my mistake... wrong table name.
        it really contains "option"
        - how can i check if there is value in query string, and if there's none,
        use default table?
        [color=blue]
        >
        > With page.php?option =page1 will fill $_GET['option'] with 'page1'
        >
        >
        > --
        > http://home.mysth.be/~timvw[/color]


        Comment

        • William Holroyd

          #5
          Re: problem with sending value to php page via url - HELP!

          [color=blue]
          > thanks it looks like my mistake... wrong table name.
          > it really contains "option"
          > - how can i check if there is value in query string, and if there's none,
          > use default table?
          >[/color]

          There are different ways of checking, this just checks to see if there is
          any value at all and if not, sets it.

          if (!$_SERVER['QUERY_STRING']) { $default_table = "default_value" ; }


          Comment

          • Tim Van Wassenhove

            #6
            Re: problem with sending value to php page via url - HELP!

            In article <c7gcsa$auh$1@l s219.htnet.hr>, ToMeK wrote:[color=blue]
            > "Tim Van Wassenhove" <euki@pi.be> wrote in message
            > news:2g1k7cF2sh e7U2@uni-berlin.de...[color=green]
            >> In article <2g1hpeF3eka5U2 @uni-berlin.de>, Pedro Graca wrote:[color=darkred]
            >> > ToMeK wrote:
            >> >> i have php page that displays records from mysql base.
            >> >> on that page i have link like this:
            >> >>
            >> >> <a href="mypage.ph p?option1">opti on1</a>
            >> >
            >> ><a href="mypage.ph p?db=option1">o ption1</a>
            >> >
            >> >> ("option1" is name of one of my tables in db)
            >> >>
            >> >> now i want to load that page and assign this value "option1" as string[/color][/color]
            > to[color=green][color=darkred]
            >> >> my variable "table".
            >> >> I tried this:
            >> >>
            >> >>
            >> >> $table=$_SERVER['QUERY_STRING'];
            >> >
            >> > $table = isset($_GET['db']) ? $_GET['db'] : 'default_table' ;[/color]
            >>
            >> If the man requests page.php?option $_GET will be empty.
            >> But when i test here, $_SERVER['QUERY_STRING'] contains 'option'[/color]
            >
            > thanks it looks like my mistake... wrong table name.
            > it really contains "option"
            > - how can i check if there is value in query string, and if there's none,
            > use default table?[/color]

            If you looked carefully at the code, you would have noticed that there
            was a isset function in use.

            --

            Comment

            Working...