...

View Full Version : URL parsing to get variables name



asgozzi
01-23-2007, 05:29 PM
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:

<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

_Aerospace_Eng_
01-23-2007, 05:51 PM
Variables sent through the URL use $_GET so you can do something like this in your 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.

asgozzi
01-23-2007, 08:32 PM
Variables sent through the URL use $_GET so you can do something like this in your 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

$1 = $_GET['1'];
$2 = $_GET['2'];
$3 = $_GET['3'];
and so on.
what I need is the name of the checkbox, not its contents.can it be done?

GJay
01-23-2007, 08:43 PM
if you name your form elements like:


<input type="checkbox" name="checkboxes[$id]" />

then (with a get-method), $_GET['checkboxes'] will be an array of values, something like


$_GET['checkboxes'] = array( '205'=>'on','206'=>'on','300'=>'on');

which you can loop through, and act on the ids, something like:


foreach($_GET['checkboxes'] as $id=>$ignore) {
echo $id; //or whatever
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum