1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How Do I Use URL Variables?

Discussion in 'PHP' started by interwho, Aug 17, 2010.

  1. #1
    Hi DPers,

    I want to create an API that uses a single variable within the URL.

    ie: lookup.php?var1=VARIABLE1

    I also want the script to log the variable to a mysql database.

    How do I get the script to read the variable, use it, and log it to a database? I searched everywhere and couldn't find an answer...
    (sorry, I'm a PHP noob :))

    EDIT: I also want to turn the variable into $variable within the script. Is this possible?
     
    Last edited: Aug 17, 2010
    interwho, Aug 17, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    You use $_GET['var1'] there yo. Like this
    
    <?php
    if(isset($_GET['var1'])) {
       $lol = $_GET['var1'];
       echo $lol;
       echo $_GET['var1'];
    }
    ?>
    
    PHP:
    I suggest that you read this tutorial from top to bottom. :) And be patient
     
    Rainulf, Aug 17, 2010 IP
    interwho likes this.
  3. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    Can I use this method with multiple variables such as query.php?var1=VARIABLE1&var2=VARIABLE2 ?

    And would the code be this:

    
    <?php
    if(isset($_GET['var1'])) {
       $lol = $_GET['var1'];
    }
    if(isset($_GET['var2'])) {
       $lol2 = $_GET['var2'];
    }
    echo $lol;
    echo $lol2;
    ?>
    
    PHP:
    ???
     
    Last edited: Aug 17, 2010
    interwho, Aug 17, 2010 IP
  4. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #4
    Try it and you'll see. ;)
     
    Rainulf, Aug 17, 2010 IP
  5. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #5
    Thanks! It Worked!
     
    interwho, Aug 17, 2010 IP
  6. azarat

    azarat Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Notie that if one of the variables is not set you will get an error when trying to echo one of them. You should echo it inside the if statements :)
     
    azarat, Aug 17, 2010 IP
  7. shazfa

    shazfa Member

    Messages:
    104
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #7
    hello,

    I am developing a site, everything fine till url rewrite but my url rewrite function is not working now.. my urls seems like rentalnetworks.com/main-1-sub-2-cisco-network-switches.html, i have to remove main-1-sub-2- to make seo friendly urls.. would you please give me solutions for this.
     
    shazfa, Aug 17, 2010 IP