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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2006
    Location
    Italy
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    URL parsing to get variables name

    hi.
    maybe the solution to my problem is quite obvious but I can't find it, so I'm asking here.I'm building a small movie db with the chance for users to borrow the title they want.
    the movies' info is fetched from a db and displayed in a html table.
    this table has a column containing a checkbox named as the numeric ID of the movie:
    PHP Code:
    <input name="'.$id.'" type="checkbox"
    now, I want to create a confirmation page before the user sends in the form with what he/she wants to borrow, but I can't figure out how to parse the URL.
    when I submit the form with POST method, I get something like this:order_preview.php?name=Andrea&205=on&206=on&Submit=Send
    I can see that the numbers represent the checkboxes selected but how do I parse the URL to get those numbers and not the "on" value?

    thanks

    Andrea

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Variables sent through the URL use $_GET so you can do something like this in your code
    PHP Code:
    $name $_GET['name'];
    $
    205 $_GET['205']; // not sure if your variables can start with a number, look into that
    $206 $_GET['206'];
    $Submit $_GET['Submit']; 
    From the looks of things though you aren't using the POST method otherwise your url wouldn't look like that. It looks like you are using GET. You may want to do some validation on the server side to ensure that the $_GET variables are variables that you want other wise users could try sending malicious code.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New to the CF scene
    Join Date
    Sep 2006
    Location
    Italy
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Variables sent through the URL use $_GET so you can do something like this in your code
    PHP Code:
    $name $_GET['name'];
    $
    205 $_GET['205']; // not sure if your variables can start with a number, look into that
    $206 $_GET['206'];
    $Submit $_GET['Submit']; 
    From the looks of things though you aren't using the POST method otherwise your url wouldn't look like that. It looks like you are using GET. You may want to do some validation on the server side to ensure that the $_GET variables are variables that you want other wise users could try sending malicious code.
    yep seems I confused get & post.
    but I know how to retrieve a variable, it's just that the db hase 400+ entries and there is no way I write
    PHP Code:
    $$_GET['1'];
    $
    $_GET['2'];
    $
    $_GET['3']; 
    and so on.
    what I need is the name of the checkbox, not its contents.can it be done?

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    if you name your form elements like:
    Code:
    <input type="checkbox" name="checkboxes[$id]" />
    then (with a get-method), $_GET['checkboxes'] will be an array of values, something like
    Code:
    $_GET['checkboxes'] = array( '205'=>'on','206'=>'on','300'=>'on');
    which you can loop through, and act on the ids, something like:
    PHP Code:
    foreach($_GET['checkboxes'] as $id=>$ignore) {
      echo 
    $id//or whatever

    Last edited by GJay; 01-23-2007 at 07:43 PM. Reason: typo
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com


  •  

    Posting Permissions

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