Call PHP Variable Before Its Given A Value?

Hi Guys,

I need your help please, please take a look at some of my code below:


<form id="form1" name="form1" method="post" action="viewaffiliates.php?affid=<? echo $AffID; ?>">
<table width="60%" border="0">
  <tr>
    <td width="28%" class="accountfield">Select Affiliate:</td>
    <td width="72%"><select name="SelectAffiliate" id="SelectAffiliate">
<?php
$i=0;
while ($i < $num) {
$AffID=mysql_result($result,$i,"AffID");
$FirstName=mysql_result($result,$i,"FirstName");
$LastName=mysql_result($result,$i,"LastName");
$Company=mysql_result($result,$i,"Company");
?>
      <option value="<? echo $AffID; ?>"><? echo $Company; ?></option>
<?
$i++;
}
?>  
</select>
      <input type="submit" name="Submit" id="Submit" value="Select" /></td>
  </tr>

As you can see on the first line above I’m calling a variable called $AffID before its even been given a value. Now i cant add that line of code after the PHP or else it would just create a load of new Forms depending on how many values are in my table.

Can anyone help me please so the value of the selected Option is placed in the Action url please.

Thank you in advance.

Thanks!

why are you passing the same data twice ?

You are adding it into the URL as a GET and then youve got it being selected in teh Select box as a POST.

You should only be using the POST method, like this your top form code wont be calling an undefined variable, thus removing your problem, and only one value (the one selected) will be returned.

Your pickup script will need to look for the POST value rather than the GET.

Erm… I’m not sure why I’ve done that, too much coding today i think its getting to me but yea i see where your coming from.

Changed my code to the correct way how everything should be done and have everything working. Sorry for such a stupid question haha.

Thanks alot!

sometimes it just takes a third eye :eye: