Forum Moderators: coopster

Message Too Old, No Replies

Passing variable via a Form to another PHP routine

         

AndyD

11:26 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



What am I doing wrong in this HTML FORM when trying to pass some variables to another PHP routine?

<form onSubmit="return isCurrency(frm)" name="frm" action="add.php?sortlist=$sortlist&category=$category" method="post">

Where $sortlist and $category are variables being passed between different PHP programs.

jatar_k

11:31 pm on Feb 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld AndyD,

I don't know where those vars are coming from but if they are available to php in that particular script you need to have them parsed to echo the values

<form onSubmit="return isCurrency(frm)" name="frm" action="add.php?sortlist=<? echo $sortlist;?>&category=<? echo $category;?>" method="post">

AndyD

11:43 pm on Feb 17, 2004 (gmt 0)

10+ Year Member



I'm new to PHP, so still learing the ropes, but have programmed in other languages. The biggest problem is the different syntax's used between ASP, PHP, VB etc.

These variables are being passed between some update routines and are used to select and sort the database. Sortlist being the sort filed and xxcategory being the selection criteria. I'm passing these between seperate add and update routines using
add.php?sortlist=$sortlist....

Using the code provided by yourself, I get the following link

[<webaddress>...]

I'm using the following to pick up the variables in the the routines

// If current sortlist, use it
// if not, set one!
if(!isset($_GET['sortlist'])){
$sortlist = brand;
} else {
$sortlist = $_GET['sortlist'];
}

// If current category, use it
// if not, set one!
if(!isset($_GET['xxcategory'])){
$xxcategory = Beer;
} else {
$xxcategory = $_GET['xxcategory'];
}

Thanks for the quick response.

Andy

jatar_k

12:01 am on Feb 18, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



ok, it would seem then that I am missing something

the form tag where you are trying to echo the vars is located in a php parsable file?

AndyD

12:10 am on Feb 18, 2004 (gmt 0)

10+ Year Member



Jatar_k,

What a star you are..... All that was wrong was that the add-form.html files should have been named add-form.php! Well, that's 2 hours it's taken me to sort that one out.. with your help of course. Atleast I was on the right track with the code.

What fun PHP is ;) It's great to be programming again.

Cheers,

Andy

willybfriendly

12:19 am on Feb 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since you are already using a form, wouldn't it be easier to pass the variable as a hidden form field than in the url? Makes the urls look nicer too :)

WBF

jetboy_70

12:19 am on Feb 18, 2004 (gmt 0)

10+ Year Member



Possibly use a <?php opening tag instead of just a <?, because it looks like the latter isn't being picked up.

Even so, you've got a mix of the GET and POST actions which is confusing you. Add your variables as form items (which can then be accessed through the $_GET array:

<input name="sortlist" type="hidden" value="<?php echo $sortlist;?>">

which can be accessed using $_GET['sortlist'].

I *think* you can only have variables attached to the URL if you use POST to access the page (through a regular HTML link), in which case you'd use the $_POST array instead of $_GET. I am willing to be proved wrong here though ...

Edit: Too many posts, too little time :0 Andy, can you pull the vars off the URL string using your approach? Does it work as you'd hoped?

jetboy_70

5:44 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



Please disregard my early hours ramblings. Obviously complete bo**ocks. Still, did this work as expected?

AndyD

7:07 pm on Feb 18, 2004 (gmt 0)

10+ Year Member



I think I'm in business. It's looking good.

I'll try your method to see if it works on the add and update form.

Many thanks for you advice, it is appreciated.

Andy